MCPcopy Create free account
hub / github.com/csxmli2016/MARCONetPlusPlus / imread_uint

Function imread_uint

utils/utils_image.py:48–65  ·  view source on GitHub ↗
(path, n_channels=3)

Source from the content-addressed store, hash-verified

46# get uint8 image of size HxWxn_channles (RGB)
47# --------------------------------------------
48def imread_uint(path, n_channels=3):
49 # input: path
50 # output: HxWx3(RGB or GGG), or HxWx1 (G)
51 if n_channels == 1:
52 img = cv2.imread(path, 0) # cv2.IMREAD_GRAYSCALE
53 img = np.expand_dims(img, axis=2) # HxWx1
54 elif n_channels == 3:
55 # img = cv2.imread(path, cv2.IMREAD_UNCHANGED) # BGR or G
56 img = cv2.imread(path) # BGR or G
57 if img is None:
58 import PIL
59 img = np.array(PIL.Image.open(path).convert('RGB'))
60 return img
61 if img.ndim == 2:
62 img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) # GGG
63 else:
64 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # RGB
65 return img
66
67def imsave(img, img_path):
68 img = np.squeeze(img)

Callers 1

inferenceFunction · 0.90

Calls

no outgoing calls

Tested by 1

inferenceFunction · 0.72