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

Function preprocess_image

tests/testing_utils.py:944–951  ·  view source on GitHub ↗
(image: PIL.Image, batch_size: int)

Source from the content-addressed store, hash-verified

942
943
944def preprocess_image(image: PIL.Image, batch_size: int):
945 w, h = image.size
946 w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8
947 image = image.resize((w, h), resample=PIL.Image.LANCZOS)
948 image = np.array(image).astype(np.float32) / 255.0
949 image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size)
950 image = torch.from_numpy(image)
951 return 2.0 * image - 1.0
952
953
954def export_to_gif(image: list[PIL.Image.Image], output_gif_path: str = None) -> str:

Callers

nothing calls this directly

Calls 2

transposeMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…