(image, file_name)
| 132 | |
| 133 | |
| 134 | def save_image(image, file_name): |
| 135 | import_numpy() |
| 136 | import_pil() |
| 137 | if image.dtype == np.float32: |
| 138 | min = np.min(image) |
| 139 | max = np.max(image) |
| 140 | if min >= 0 and max <= 1: |
| 141 | image = image * 256 |
| 142 | elif min >= -1 and max <= 1: |
| 143 | image = (image + 1) * 128 |
| 144 | elif min >= -128 and max <= 127: |
| 145 | image = image + 128 |
| 146 | else: |
| 147 | lo = np.iinfo(image.dtype).min |
| 148 | hi = np.iinfo(image.dtype).max |
| 149 | image = (image - lo) * (255.0 / (hi - lo)) |
| 150 | image = image.astype(np.uint8) |
| 151 | Image.fromarray(image).save(file_name) |
| 152 | |
| 153 | |
| 154 | def get_gpu_num(): |
no test coverage detected