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

Method numpy_to_pil

src/diffusers/image_processor.py:128–149  ·  view source on GitHub ↗

r""" Convert a numpy image or a batch of images to a PIL image. Args: images (`np.ndarray`): The image array to convert to PIL format. Returns: `list[PIL.Image.Image]`: A list of PIL images.

(images: np.ndarray)

Source from the content-addressed store, hash-verified

126
127 @staticmethod
128 def numpy_to_pil(images: np.ndarray) -> list[PIL.Image.Image]:
129 r"""
130 Convert a numpy image or a batch of images to a PIL image.
131
132 Args:
133 images (`np.ndarray`):
134 The image array to convert to PIL format.
135
136 Returns:
137 `list[PIL.Image.Image]`:
138 A list of PIL images.
139 """
140 if images.ndim == 3:
141 images = images[None, ...]
142 images = (images * 255).round().astype("uint8")
143 if images.shape[-1] == 1:
144 # special case for grayscale (single channel) images
145 pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
146 else:
147 pil_images = [Image.fromarray(image) for image in images]
148
149 return pil_images
150
151 @staticmethod
152 def pil_to_numpy(images: list[PIL.Image.Image] | PIL.Image.Image) -> np.ndarray:

Callers 15

postprocessMethod · 0.95
convert_pt_to_typeMethod · 0.45
get_dummy_inputsMethod · 0.45
__call__Method · 0.45
__call__Method · 0.45
mainFunction · 0.45
log_validationFunction · 0.45
generateFunction · 0.45
generateFunction · 0.45
run_safety_checkerMethod · 0.45

Calls

no outgoing calls

Tested by 4

convert_pt_to_typeMethod · 0.36
get_dummy_inputsMethod · 0.36