64 img = np.asarray(img, dtype=np.float32).copy()
68 for attempt
in range(100):
69 area = img.shape[0] * img.shape[1]
70 target_area = random.uniform(self.
sl, self.
sh) * area
71 aspect_ratio = random.uniform(self.
r1, 1 / self.
r1)
73 h = int(round(math.sqrt(target_area * aspect_ratio)))
74 w = int(round(math.sqrt(target_area / aspect_ratio)))
76 if w < img.shape[1]
and h < img.shape[0]:
77 x1 = random.randint(0, img.shape[0] - h)
78 y1 = random.randint(0, img.shape[1] - w)
80 img[x1:x1 + h, y1:y1 + w, 0] = self.
mean[0]
81 img[x1:x1 + h, y1:y1 + w, 1] = self.
mean[1]
82 img[x1:x1 + h, y1:y1 + w, 2] = self.
mean[2]
84 img[x1:x1 + h, y1:y1 + w, 0] = self.
mean[0]