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

Method pil_to_numpy

src/diffusers/image_processor.py:152–169  ·  view source on GitHub ↗

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

(images: list[PIL.Image.Image] | PIL.Image.Image)

Source from the content-addressed store, hash-verified

150
151 @staticmethod
152 def pil_to_numpy(images: list[PIL.Image.Image] | PIL.Image.Image) -> np.ndarray:
153 r"""
154 Convert a PIL image or a list of PIL images to NumPy arrays.
155
156 Args:
157 images (`PIL.Image.Image` or `list[PIL.Image.Image]`):
158 The PIL image or list of images to convert to NumPy format.
159
160 Returns:
161 `np.ndarray`:
162 A NumPy array representation of the images.
163 """
164 if not isinstance(images, list):
165 images = [images]
166 images = [np.array(image).astype(np.float32) / 255.0 for image in images]
167 images = np.stack(images, axis=0)
168
169 return images
170
171 @staticmethod
172 def numpy_to_pt(images: np.ndarray) -> torch.Tensor:

Callers 14

preprocessMethod · 0.95
test_kandinskyV3Method · 0.95
preprocessMethod · 0.80
_encode_imageMethod · 0.80
preprocess_imageMethod · 0.80
_encode_imageMethod · 0.80
test_sdv1_5_lcm_loraMethod · 0.80
test_sdxl_lcm_loraMethod · 0.80

Calls

no outgoing calls

Tested by 8

test_kandinskyV3Method · 0.76
test_sdv1_5_lcm_loraMethod · 0.64
test_sdxl_lcm_loraMethod · 0.64
convert_to_ptMethod · 0.64