Write `data` as image to `url`
(url, data, mode='RGB', name=None)
| 176 | |
| 177 | |
| 178 | def imwrite(url, data, mode='RGB', name=None): |
| 179 | """Write `data` as image to `url`""" |
| 180 | |
| 181 | url = Path(url) |
| 182 | if not url.exists(): |
| 183 | url.mkdir(parents=True, exist_ok=True) |
| 184 | if np.ndim(data) == 3: |
| 185 | data = np.expand_dims(data, 0) |
| 186 | imgs = np.split(data, data.shape[0]) |
| 187 | if name is None: |
| 188 | name = ['image_{:03d}'.format(i) for i in range(data.shape[0])] |
| 189 | urls = to_list(url, data.shape[0]) |
| 190 | for img, url, n in zip(imgs, urls, name): |
| 191 | if url.is_dir(): |
| 192 | url_f = url / n |
| 193 | else: |
| 194 | url_f = url |
| 195 | img = array_to_img(img[0], mode).convert('RGB') |
| 196 | url_f = url_f.with_suffix('.png') |
| 197 | if url_f.exists(): |
| 198 | url_f = url_f.parent / (url_f.stem + str(np.random.randint(100000))) |
| 199 | url_f = url_f.with_suffix('.png') |
| 200 | img.save(url_f) |
| 201 | |
| 202 | |
| 203 | def random_crop_batch_image(image, batch, shape, seed=None): |
nothing calls this directly
no test coverage detected