(image_numpy, image_path, create_dir=False)
| 126 | |
| 127 | |
| 128 | def save_image(image_numpy, image_path, create_dir=False): |
| 129 | if create_dir: |
| 130 | os.makedirs(os.path.dirname(image_path), exist_ok=True) |
| 131 | if len(image_numpy.shape) == 2: |
| 132 | image_numpy = np.expand_dims(image_numpy, axis=2) |
| 133 | if image_numpy.shape[2] == 1: |
| 134 | image_numpy = np.repeat(image_numpy, 3, 2) |
| 135 | image_pil = Image.fromarray(image_numpy) |
| 136 | |
| 137 | # save to png |
| 138 | image_pil.save(image_path.replace('.jpg', '.png')) |
| 139 | |
| 140 | |
| 141 | def mkdirs(paths): |