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

Function preprocess_image

diffusers/examples/community/lpw_stable_diffusion.py:406–413  ·  view source on GitHub ↗
(image, batch_size)

Source from the content-addressed store, hash-verified

404
405
406def preprocess_image(image, batch_size):
407 w, h = image.size
408 w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8
409 image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"])
410 image = np.array(image).astype(np.float32) / 255.0
411 image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size)
412 image = torch.from_numpy(image)
413 return 2.0 * image - 1.0
414
415
416def preprocess_mask(mask, batch_size, scale_factor=8):

Callers 1

__call__Method · 0.70

Calls 2

transposeMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected