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

Function imread

scripts/util_image.py:312–340  ·  view source on GitHub ↗

Read image. chn: 'rgb', 'bgr' or 'gray' out: im: h x w x c, numpy tensor

(path, chn='rgb', dtype='float32')

Source from the content-addressed store, hash-verified

310
311# ------------------------Image I/O-----------------------------
312def imread(path, chn='rgb', dtype='float32'):
313 '''
314 Read image.
315 chn: 'rgb', 'bgr' or 'gray'
316 out:
317 im: h x w x c, numpy tensor
318 '''
319 im = cv2.imread(str(path), cv2.IMREAD_UNCHANGED) # BGR, uint8
320 try:
321 if chn.lower() == 'rgb':
322 if im.ndim == 3:
323 im = bgr2rgb(im)
324 else:
325 im = np.stack((im, im, im), axis=2)
326 elif chn.lower() == 'gray':
327 assert im.ndim == 2
328 except:
329 print(str(path))
330
331 if dtype == 'float32':
332 im = im.astype(np.float32) / 255.
333 elif dtype == 'float64':
334 im = im.astype(np.float64) / 255.
335 elif dtype == 'uint8':
336 pass
337 else:
338 sys.exit('Please input corrected dtype: float32, float64 or uint8!')
339
340 return im
341
342def imwrite(im_in, path, chn='rgb', dtype_in='float32', qf=None):
343 '''

Callers

nothing calls this directly

Calls 1

bgr2rgbFunction · 0.85

Tested by

no test coverage detected