|
- import numpy as np
- import cv2
-
- def MatrixToImage(data):
- data = data * 255
- data = data.clip(0, 255)
- new_im = data.astype(np.uint8)
- return new_im
-
- def show_single(img, scale = 1):
- if img.ndim == 2:
- h, w = img.shape
- else:
- h, w, _ = img.shape
- cv2.imshow('img', cv2.resize(img, (w//scale, h//scale)))
- cv2.waitKey()
- cv2.destroyAllWindows()
-
- def photometric(img):
- trans_func = np.poly1d([2.114, -2.387, 0.9562, -0.04])
- r = quantization(trans_func(normalization(img.copy())))
- return r
-
- def normalization(img):
- return img.astype(np.float32)/255.0
-
- def quantization(img): # in (0,1) out(0,255)
- img = np.clip(img, 0, 1)
- img_oct = img * 255
- img_oct = img_oct.astype(np.uint8)
- return img_oct
-
- def make_pairs_horizontal(img_list, left = True, blank_width=10):
- if len(img_list) == 0:
- return
- else:
- num = len(img_list)
-
- for i in range(num):
- if img_list[i].ndim == 2:
- img = cv2.merge([img_list[i], img_list[i], img_list[i]])
- img_list[i] = img
-
- H, W, _ = img_list[0].shape
- blank = np.array([255]*H*blank_width, dtype = np.uint8).repeat(3)
- blank = blank.reshape((H, blank_width, 3))
-
- combined = blank.copy()
- for i in range(num):
- combined = np.hstack((combined, img_list[i], blank.copy()))
-
- H, W, _ = combined.shape
- if not left:
- combined = combined[:, blank_width:]
- else:
- combined = combined[:, blank_width:W-blank_width]
-
- return combined
|