Convert a numpy image or a batch of images to a PIL image.
(images)
| 63 | return f"{organization}/{model_id}" |
| 64 | |
| 65 | def numpy_to_pil(images): |
| 66 | """ |
| 67 | Convert a numpy image or a batch of images to a PIL image. |
| 68 | """ |
| 69 | if images.ndim == 3: |
| 70 | images = images[None, ...] |
| 71 | images = (images * 255).round().astype("uint8") |
| 72 | if images.shape[-1] == 1: |
| 73 | # special case for grayscale (single channel) images |
| 74 | pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images] |
| 75 | else: |
| 76 | pil_images = [Image.fromarray(image) for image in images] |
| 77 | |
| 78 | return pil_images |
| 79 | |
| 80 | |
| 81 | def main(): |
nothing calls this directly
no outgoing calls
no test coverage detected