MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / numpy_to_pil

Method numpy_to_pil

src/diffusers/image_processor.py:676–689  ·  view source on GitHub ↗

Convert a NumPy image or a batch of images to a PIL image.

(images: np.ndarray)

Source from the content-addressed store, hash-verified

674
675 @staticmethod
676 def numpy_to_pil(images: np.ndarray) -> List[PIL.Image.Image]:
677 """
678 Convert a NumPy image or a batch of images to a PIL image.
679 """
680 if images.ndim == 3:
681 images = images[None, ...]
682 images = (images * 255).round().astype("uint8")
683 if images.shape[-1] == 1:
684 # special case for grayscale (single channel) images
685 pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
686 else:
687 pil_images = [Image.fromarray(image[:, :, :3]) for image in images]
688
689 return pil_images
690
691 @staticmethod
692 def depth_pil_to_numpy(images: Union[List[PIL.Image.Image], PIL.Image.Image]) -> np.ndarray:

Callers 1

postprocessMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected