MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / numpy_to_pil

Function numpy_to_pil

train_diff.py:65–78  ·  view source on GitHub ↗

Convert a numpy image or a batch of images to a PIL image.

(images)

Source from the content-addressed store, hash-verified

63 return f"{organization}/{model_id}"
64
65def 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
81def main():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected