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

Function preprocess_image

diffusers/examples/community/mixture_canvas.py:20–34  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

18
19
20def preprocess_image(image):
21 from PIL import Image
22
23 """Preprocess an input image
24
25 Same as
26 https://github.com/huggingface/diffusers/blob/1138d63b519e37f0ce04e027b9f4a3261d27c628/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L44
27 """
28 w, h = image.size
29 w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
30 image = image.resize((w, h), resample=Image.LANCZOS)
31 image = np.array(image).astype(np.float32) / 255.0
32 image = image[None].transpose(0, 3, 1, 2)
33 image = torch.from_numpy(image)
34 return 2.0 * image - 1.0
35
36
37@dataclass

Callers

nothing calls this directly

Calls 2

transposeMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected