Read an image into the given format. Will apply rotation and flipping if the image has such exif information. Args: file_name (str): image file path format (str): one of the supported image modes in PIL, or "BGR" or "YUV-BT.601". Returns: image (np.ndarray)
(file_name, format=None)
| 163 | |
| 164 | |
| 165 | def read_image(file_name, format=None): |
| 166 | """ |
| 167 | Read an image into the given format. |
| 168 | Will apply rotation and flipping if the image has such exif information. |
| 169 | |
| 170 | Args: |
| 171 | file_name (str): image file path |
| 172 | format (str): one of the supported image modes in PIL, or "BGR" or "YUV-BT.601". |
| 173 | |
| 174 | Returns: |
| 175 | image (np.ndarray): an HWC image in the given format, which is 0-255, uint8 for |
| 176 | supported image modes in PIL or "BGR"; float (0-1 for Y) for YUV-BT.601. |
| 177 | """ |
| 178 | with PathManager.open(file_name, "rb") as f: |
| 179 | image = Image.open(f) |
| 180 | |
| 181 | # work around this bug: https://github.com/python-pillow/Pillow/issues/3973 |
| 182 | image = _apply_exif_orientation(image) |
| 183 | return convert_PIL_to_numpy(image, format) |
| 184 | |
| 185 | |
| 186 | def check_image_size(dataset_dict, image): |