1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| import cv2 import numpy as np from datasets.utils import MaskToTensor, get_params, affine_transform
img = cv2.imread("/home/harvey/Datasets/CFD/train_img/052.jpg") lab = cv2.imread("/home/harvey/Datasets/CFD/test_lab/035.png")
h, w = img.shape[:2]
cv2.imshow("img", img) cv2.imshow("lab", lab)
lr = np.fliplr(img) dst = np.hstack((lr, img, lr)) ud = np.flipud(dst) img = np.vstack((ud, dst, ud))
lr = np.fliplr(lab) dst = np.hstack((lr, lab, lr)) ud = np.flipud(dst) lab = np.vstack((ud, dst, ud))
angle, scale, shift = get_params() img = affine_transform(img, angle, scale, shift, w * 3, h * 3) lab = affine_transform(lab, angle, scale, shift, w * 3, h * 3) offset_h = np.random.randint(0, h / 2) offset_w = np.random.randint(0, w / 2) img = img[h + offset_h:2 * h + offset_h, w + offset_w:2 * w + offset_w, :] lab = lab[h + offset_h:2 * h + offset_h, w + offset_w:2 * w + offset_w, :]
cv2.imshow("flab", lab) cv2.imshow("fimg", img) cv2.waitKey(0)
|