MCPcopy Create free account
hub / github.com/IceClear/StableSR / imwrite

Function imwrite

scripts/util_image.py:342–364  ·  view source on GitHub ↗

Save image. Input: im: h x w x c, numpy tensor path: the saving path chn: the channel order of the im,

(im_in, path, chn='rgb', dtype_in='float32', qf=None)

Source from the content-addressed store, hash-verified

340 return im
341
342def imwrite(im_in, path, chn='rgb', dtype_in='float32', qf=None):
343 '''
344 Save image.
345 Input:
346 im: h x w x c, numpy tensor
347 path: the saving path
348 chn: the channel order of the im,
349 '''
350 im = im_in.copy()
351 if isinstance(path, str):
352 path = Path(path)
353 if dtype_in != 'uint8':
354 im = img_as_ubyte(im)
355
356 if chn.lower() == 'rgb' and im.ndim == 3:
357 im = rgb2bgr(im)
358
359 if qf is not None and path.suffix.lower() in ['.jpg', '.jpeg']:
360 flag = cv2.imwrite(str(path), im, [int(cv2.IMWRITE_JPEG_QUALITY), int(qf)])
361 else:
362 flag = cv2.imwrite(str(path), im)
363
364 return flag
365
366def jpeg_compress(im, qf, chn_in='rgb'):
367 '''

Callers

nothing calls this directly

Calls 1

rgb2bgrFunction · 0.85

Tested by

no test coverage detected