MCPcopy Create free account
hub / github.com/LoSealL/VideoSuperResolution / imwrite

Function imwrite

VSR/Util/ImageProcess.py:178–200  ·  view source on GitHub ↗

Write `data` as image to `url`

(url, data, mode='RGB', name=None)

Source from the content-addressed store, hash-verified

176
177
178def 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
203def random_crop_batch_image(image, batch, shape, seed=None):

Callers

nothing calls this directly

Calls 3

to_listFunction · 0.85
array_to_imgFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected