replace background pixel with random color in rendering
(self, path, color)
| 108 | return len(self.paths) |
| 109 | |
| 110 | def load_im(self, path, color): |
| 111 | ''' |
| 112 | replace background pixel with random color in rendering |
| 113 | ''' |
| 114 | pil_img = Image.open(path) |
| 115 | |
| 116 | image = np.asarray(pil_img, dtype=np.float32) / 255. |
| 117 | alpha = image[:, :, 3:] |
| 118 | image = image[:, :, :3] * alpha + color * (1 - alpha) |
| 119 | |
| 120 | image = torch.from_numpy(image).permute(2, 0, 1).contiguous().float() |
| 121 | alpha = torch.from_numpy(alpha).permute(2, 0, 1).contiguous().float() |
| 122 | return image, alpha |
| 123 | |
| 124 | def __getitem__(self, index): |
| 125 | while True: |