MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / read_image

Function read_image

detectron2/data/detection_utils.py:165–183  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

163
164
165def 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
186def check_image_size(dataset_dict, image):

Callers 4

_maybe_read_imageMethod · 0.90
get_sample_coco_imageFunction · 0.90
demo.pyFile · 0.90
demo.pyFile · 0.90

Calls 2

_apply_exif_orientationFunction · 0.85
convert_PIL_to_numpyFunction · 0.85

Tested by 2

_maybe_read_imageMethod · 0.72
get_sample_coco_imageFunction · 0.72