将numpy数组转换为PIL Image Args: array: numpy数组 mode: 图片模式,默认为'RGB' Returns: PIL Image对象 Raises: ImageProcessError: 当转换失败时
(array: np.ndarray, mode: str = 'RGB')
| 190 | |
| 191 | |
| 192 | def numpy_to_image(array: np.ndarray, mode: str = 'RGB') -> Image.Image: |
| 193 | """ |
| 194 | 将numpy数组转换为PIL Image |
| 195 | |
| 196 | Args: |
| 197 | array: numpy数组 |
| 198 | mode: 图片模式,默认为'RGB' |
| 199 | |
| 200 | Returns: |
| 201 | PIL Image对象 |
| 202 | |
| 203 | Raises: |
| 204 | ImageProcessError: 当转换失败时 |
| 205 | """ |
| 206 | try: |
| 207 | return Image.fromarray(array, mode=mode) |
| 208 | except Exception as e: |
| 209 | raise ImageProcessError(f"numpy数组转图片失败: {str(e)}") from e |
no test coverage detected
searching dependent graphs…