MCPcopy
hub / github.com/deep-floyd/IF / _prepare_pil_image

Function _prepare_pil_image

deepfloyd_if/pipelines/utils.py:8–25  ·  view source on GitHub ↗
(raw_pil_img, img_size)

Source from the content-addressed store, hash-verified

6
7
8def _prepare_pil_image(raw_pil_img, img_size):
9 raw_pil_img = raw_pil_img.convert('RGB')
10 w, h = raw_pil_img.size
11 coef = w / h
12 image_h, image_w = img_size, img_size
13 if coef >= 1:
14 image_w = int(round(img_size / 8 * coef) * 8)
15 else:
16 image_h = int(round(img_size / 8 / coef) * 8)
17
18 pil_img = raw_pil_img.resize(
19 (image_w, image_h), resample=getattr(Image, 'Resampling', Image).BICUBIC, reducing_gap=None
20 )
21 img = np.array(pil_img)
22 img = img.astype(np.float32) / 127.5 - 1
23 img = np.transpose(img, [2, 0, 1])
24 img = torch.from_numpy(img).unsqueeze(0)
25 return img

Callers 3

style_transferFunction · 0.85
super_resolutionFunction · 0.85
inpaintingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected