replace background pixel with random color in rendering
(self, path, color)
| 278 | return len(self.paths) |
| 279 | |
| 280 | def load_im(self, path, color): |
| 281 | ''' |
| 282 | replace background pixel with random color in rendering |
| 283 | ''' |
| 284 | pil_img = Image.open(path) |
| 285 | pil_img = pil_img.resize((self.input_image_size, self.input_image_size), resample=Image.BICUBIC) |
| 286 | |
| 287 | image = np.asarray(pil_img, dtype=np.float32) / 255. |
| 288 | if image.shape[-1] == 4: |
| 289 | alpha = image[:, :, 3:] |
| 290 | image = image[:, :, :3] * alpha + color * (1 - alpha) |
| 291 | else: |
| 292 | alpha = np.ones_like(image[:, :, :1]) |
| 293 | |
| 294 | image = torch.from_numpy(image).permute(2, 0, 1).contiguous().float() |
| 295 | alpha = torch.from_numpy(alpha).permute(2, 0, 1).contiguous().float() |
| 296 | return image, alpha |
| 297 | |
| 298 | def __getitem__(self, index): |
| 299 | # load data |