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

Method numpy_to_pil

src/diffusers/image_processor.py:86–99  ·  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

84
85 @staticmethod
86 def numpy_to_pil(images: np.ndarray) -> List[PIL.Image.Image]:
87 """
88 Convert a numpy image or a batch of images to a PIL image.
89 """
90 if images.ndim == 3:
91 images = images[None, ...]
92 images = (images * 255).round().astype("uint8")
93 if images.shape[-1] == 1:
94 # special case for grayscale (single channel) images
95 pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
96 else:
97 pil_images = [Image.fromarray(image) for image in images]
98
99 return pil_images
100
101 @staticmethod
102 def pil_to_numpy(images: Union[List[PIL.Image.Image], PIL.Image.Image]) -> np.ndarray:

Callers 15

postprocessMethod · 0.95
convert_pt_to_typeMethod · 0.45
test_dummy_all_tpusMethod · 0.45
get_dummy_inputsMethod · 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

Calls

no outgoing calls

Tested by 6

convert_pt_to_typeMethod · 0.36
test_dummy_all_tpusMethod · 0.36
get_dummy_inputsMethod · 0.36
get_dummy_inputsMethod · 0.36