MCPcopy
hub / github.com/kohya-ss/sd-scripts / preprocess_image

Function preprocess_image

gen_img.py:1338–1345  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

1336
1337
1338def preprocess_image(image):
1339 w, h = image.size
1340 w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
1341 image = image.resize((w, h), resample=PIL.Image.LANCZOS)
1342 image = np.array(image).astype(np.float32) / 255.0
1343 image = image[None].transpose(0, 3, 1, 2)
1344 image = torch.from_numpy(image)
1345 return 2.0 * image - 1.0
1346
1347
1348def preprocess_mask(mask):

Callers 1

__call__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected