MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / preprocess_image

Function preprocess_image

diffusers/src/diffusers/utils/testing_utils.py:498–505  ·  view source on GitHub ↗
(image: PIL.Image, batch_size: int)

Source from the content-addressed store, hash-verified

496
497
498def preprocess_image(image: PIL.Image, batch_size: int):
499 w, h = image.size
500 w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8
501 image = image.resize((w, h), resample=PIL.Image.LANCZOS)
502 image = np.array(image).astype(np.float32) / 255.0
503 image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size)
504 image = torch.from_numpy(image)
505 return 2.0 * image - 1.0
506
507
508def 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