MCPcopy Create free account
hub / github.com/DragonisCV/RAM / imfrombytes

Function imfrombytes

ram/utils/img_util.py:114–132  ·  view source on GitHub ↗

Read an image from bytes. Args: content (bytes): Image bytes got from files or other streams. flag (str): Flags specifying the color type of a loaded image, candidates are `color`, `grayscale` and `unchanged`. float32 (bool): Whether to change to float32., If

(content, flag='color', float32=False)

Source from the content-addressed store, hash-verified

112
113
114def imfrombytes(content, flag='color', float32=False):
115 """Read an image from bytes.
116
117 Args:
118 content (bytes): Image bytes got from files or other streams.
119 flag (str): Flags specifying the color type of a loaded image,
120 candidates are `color`, `grayscale` and `unchanged`.
121 float32 (bool): Whether to change to float32., If True, will also norm
122 to [0, 1]. Default: False.
123
124 Returns:
125 ndarray: Loaded image array.
126 """
127 img_np = np.frombuffer(content, np.uint8)
128 imread_flags = {'color': cv2.IMREAD_COLOR, 'grayscale': cv2.IMREAD_GRAYSCALE, 'unchanged': cv2.IMREAD_UNCHANGED}
129 img = cv2.imdecode(img_np, imread_flags[flag])
130 if float32:
131 img = img.astype(np.float32) / 255.
132 return img
133
134
135def imwrite(img, file_path, params=None, auto_mkdir=True):

Callers 3

_load_imageMethod · 0.90
_load_imageMethod · 0.90
_load_imageMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected