MCPcopy Create free account
hub / github.com/DIVE128/DMVSNet / RandomCrop

Class RandomCrop

datasets/data_io.py:74–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73import random, cv2
74class RandomCrop(object):
75 def __init__(self, CropSize=0.1):
76 self.CropSize = CropSize
77
78 def __call__(self, image, normal):
79 h, w = normal.shape[:2]
80 img_h, img_w = image.shape[:2]
81 CropSize_w, CropSize_h = max(1, int(w * self.CropSize)), max(1, int(h * self.CropSize))
82 x1, y1 = random.randint(0, CropSize_w), random.randint(0, CropSize_h)
83 x2, y2 = random.randint(w - CropSize_w, w), random.randint(h - CropSize_h, h)
84
85 normal_crop = normal[y1:y2, x1:x2]
86 normal_resize = cv2.resize(normal_crop, (w, h), interpolation=cv2.INTER_NEAREST)
87
88 image_crop = image[4*y1:4*y2, 4*x1:4*x2]
89 image_resize = cv2.resize(image_crop, (img_w, img_h), interpolation=cv2.INTER_LINEAR)
90
91 # import matplotlib.pyplot as plt
92 # plt.subplot(2, 3, 1)
93 # plt.imshow(image)
94 # plt.subplot(2, 3, 2)
95 # plt.imshow(image_crop)
96 # plt.subplot(2, 3, 3)
97 # plt.imshow(image_resize)
98 #
99 # plt.subplot(2, 3, 4)
100 # plt.imshow((normal + 1.0) / 2, cmap="rainbow")
101 # plt.subplot(2, 3, 5)
102 # plt.imshow((normal_crop + 1.0) / 2, cmap="rainbow")
103 # plt.subplot(2, 3, 6)
104 # plt.imshow((normal_resize + 1.0) / 2, cmap="rainbow")
105 # plt.show()
106 # plt.pause(1)
107 # plt.close()
108
109 return image_resize, normal_resize
110def cv2_imread(filename):
111 return cv2.imread(filename,0)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected