MCPcopy Create free account
hub / github.com/AlayaLab/Hive / numpy_to_pil

Function numpy_to_pil

models/flowsep/diffusers/utils/pil_utils.py:32–45  ·  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

30
31
32def numpy_to_pil(images):
33 """
34 Convert a numpy image or a batch of images to a PIL image.
35 """
36 if images.ndim == 3:
37 images = images[None, ...]
38 images = (images * 255).round().astype("uint8")
39 if images.shape[-1] == 1:
40 # special case for grayscale (single channel) images
41 pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
42 else:
43 pil_images = [Image.fromarray(image) for image in images]
44
45 return pil_images

Callers 2

pt_to_pilFunction · 0.85
numpy_to_pilMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected