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

Function numpy_to_pil

diffusers/src/diffusers/utils/pil_utils.py:37–50  ·  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

35
36
37def numpy_to_pil(images):
38 """
39 Convert a numpy image or a batch of images to a PIL image.
40 """
41 if images.ndim == 3:
42 images = images[None, ...]
43 images = (images * 255).round().astype("uint8")
44 if images.shape[-1] == 1:
45 # special case for grayscale (single channel) images
46 pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
47 else:
48 pil_images = [Image.fromarray(image) for image in images]
49
50 return pil_images
51
52
53def make_image_grid(images: List[PIL.Image.Image], rows: int, cols: int, resize: int = None) -> PIL.Image.Image:

Callers 3

postprocessMethod · 0.90
pt_to_pilFunction · 0.70
numpy_to_pilMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected