MCPcopy Index your code
hub / github.com/huggingface/diffusers / numpy_to_pil

Function numpy_to_pil

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

33
34
35def numpy_to_pil(images):
36 """
37 Convert a numpy image or a batch of images to a PIL image.
38 """
39 if images.ndim == 3:
40 images = images[None, ...]
41 images = (images * 255).round().astype("uint8")
42 if images.shape[-1] == 1:
43 # special case for grayscale (single channel) images
44 pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
45 else:
46 pil_images = [Image.fromarray(image) for image in images]
47
48 return pil_images
49
50
51def 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.85
numpy_to_pilMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…