MCPcopy
hub / github.com/sml2h3/ddddocr / image_to_numpy

Function image_to_numpy

ddddocr/utils/image_io.py:170–189  ·  view source on GitHub ↗

将PIL Image转换为numpy数组 Args: image: PIL Image对象 target_mode: 目标颜色模式,默认为'RGB' Returns: numpy数组 Raises: ImageProcessError: 当转换失败时

(image: Image.Image, target_mode: str = 'RGB')

Source from the content-addressed store, hash-verified

168
169
170def image_to_numpy(image: Image.Image, target_mode: str = 'RGB') -> np.ndarray:
171 """
172 将PIL Image转换为numpy数组
173
174 Args:
175 image: PIL Image对象
176 target_mode: 目标颜色模式,默认为'RGB'
177
178 Returns:
179 numpy数组
180
181 Raises:
182 ImageProcessError: 当转换失败时
183 """
184 try:
185 if image.mode != target_mode:
186 image = image.convert(target_mode)
187 return np.array(image)
188 except Exception as e:
189 raise ImageProcessError(f"图片转numpy数组失败: {str(e)}") from e
190
191
192def numpy_to_image(array: np.ndarray, mode: str = 'RGB') -> Image.Image:

Callers 7

filter_imageMethod · 0.85
get_maskMethod · 0.85
normalize_imageMethod · 0.85
remove_noiseMethod · 0.85
binarize_imageMethod · 0.85
slide_matchMethod · 0.85
slide_comparisonMethod · 0.85

Calls 1

ImageProcessErrorClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…