image_load
data.transform.image_load
ImageLoader
여러 형태의 데이터를 입력으로 받아, 전처리 과정을 거쳐 PIL Image 혹은 np.ndarray 로 return 합니다. 현재 지원하는 데이터는 다음과 같습니다. - 데이터 타입: [image path, np.ndarray, PIL Image] - color: ["RGB", "Gray"] - bit: [8, 16]
입력으로 받은 데이터에 따른 출력값은 다음과 같습니다. | image path | np.ndarray | PIL | RGB; 8 | PIL(RGB;8) | PIL(RGB;8) | PIL(RGB;8) | RGB;16 | PIL(RGB;8) | PIL(RGB;8) | - | Gray; 8 | PIL(L;8) | PIL(L;8) | PIL(L;8) | Gray;16 | PIL(L;8) | PIL(L;8) | PIL(L;8) |
Note1
PIL은 RGB;16을 지원하지 않습니다. 따라서 PIL(RGB;16)은 입력으로 들어올 수 없습니다.
Note2
PIL은 "I;16" 모드로 Gray;16을 지원하지만, PIL 내부의 convert 함수를 써서 Gray;8로 변환시 값이 overflow 나는 issue가 있습니다.
Note3
이미지는 기본적으로 np.ndarray로 로드되며, PIL.Image.Image로 로드하려면 to_numpy=False를 세팅하세요.
Note4
image_mode는 "RGB", "L" 중 하나를 지원하며, multipage (이미지 리스트) 인 경우 각 페이지의 모드를 리스트로 입력하세요.
예시: 1, 3번째 페이지는 RGB 이고 2번째 페이지는 L 인 경우 image_mode = ["RGB", "L", "RGB"]
Source code in SaigeToolkit/data/transform/image_load.py
call_method
make [PIL Image or np.ndarray] from PIL.Image, np.ndarray, or path string
Parameters:
-
image(Union[Image, ndarray, str, List]) –PIL.Image, array, path string or list of it.
Returns:
-
Dict(Dict) –{ "image": Union[PIL.Image.Image, np.ndarray, List[PIL.Image.Image], List[np.ndarray]], **input_dict, }
Source code in SaigeToolkit/data/transform/image_load.py
load_from_path
Loading function using PIL.Image library. This function is introduced because {exif_transpose} must be processed. {exif_transpose} fix rotated image binary data using {EXIF} information. Without {exif_transpose}, network would accidently learn randomly rotated image data.
Parameters:
-
path(str) –path to image file
Returns:
-
Union[Image, ndarray]–Union[Image.Image, np.ndarray]: image
Source code in SaigeToolkit/data/transform/image_load.py
_convert_16_to_8
staticmethod
이미지 픽셀당 비트수를 16에서 8로 변화합니다. 입출력 데이터 타입이 같습니다. (pil로 받으면 pil을 ndarray로 받을 시 ndarray를 출력합니다.)
Source code in SaigeToolkit/data/transform/image_load.py
convert_image_mode
convert_image_mode(image: Union[Image, ndarray], mode: str, copy: bool = False) -> Union[Image, ndarray]
convert image mode
Parameters:
-
image(Union[Image, ndarray]) –image
-
mode(str) –"RGB" or "L"
-
copy(bool, default:False) –to copy data. Defaults to False.
Returns:
-
Union[Image, ndarray]–Union[Image.Image, np.ndarray]: converted image
Note
RGB -> L 변환 시 Image.Image와 np.ndarray 연산 결과가 다를 수 있음. (PIL과 cv2 에서 변환식은 L = R * 299/1000 + G * 587/1000 + B * 114/1000 로 동일하나 소숫점 처리 방식이 다름)
Source code in SaigeToolkit/data/transform/image_function.py
read_image_size
read_image_size(image: Union[Image, Tensor, ndarray]) -> ImageSizeType
image size: (W, H)