New image corruptor gradations

This commit is contained in:
James Betker 2020-10-15 10:12:25 -06:00
parent 1f20d59c31
commit 0f4e03183f

View File

@ -47,11 +47,14 @@ class ImageCorruptor:
img = img / 255 img = img / 255
elif 'gaussian_blur' in aug: elif 'gaussian_blur' in aug:
# Gaussian Blur # Gaussian Blur
kernel = 2 * self.blur_scale * (rand_int % 3) + 1 if aug == 'gaussian_blur_3':
kernel = 3
else:
kernel = 2 * self.blur_scale * (rand_int % 3) + 1
img = cv2.GaussianBlur(img, (kernel, kernel), 3) img = cv2.GaussianBlur(img, (kernel, kernel), 3)
elif 'motion_blur' in aug: elif 'motion_blur' in aug:
# Motion blur # Motion blur
intensity = 2 * self.blur_scale * (rand_int % 3) + 1 intensity = self.blur_scale * (rand_int % 3) + 1
angle = (rand_int // 3) % 360 angle = (rand_int // 3) % 360
k = np.zeros((intensity, intensity), dtype=np.float32) k = np.zeros((intensity, intensity), dtype=np.float32)
k[(intensity - 1) // 2, :] = np.ones(intensity, dtype=np.float32) k[(intensity - 1) // 2, :] = np.ones(intensity, dtype=np.float32)
@ -79,8 +82,11 @@ class ImageCorruptor:
# Chromatic aberration # Chromatic aberration
pass pass
elif 'noise' in aug: elif 'noise' in aug:
# Block noise # Random noise
noise_intensity = (rand_int % 4 + 2) / 255.0 # Between 1-4 if 'noise-5' == aug:
noise_intensity = 5 / 255.0
else:
noise_intensity = (rand_int % 4 + 2) / 255.0 # Between 1-4
img += np.random.randn(*img.shape) * noise_intensity img += np.random.randn(*img.shape) * noise_intensity
elif 'jpeg' in aug: elif 'jpeg' in aug:
if aug == 'jpeg': if aug == 'jpeg':
@ -89,6 +95,9 @@ class ImageCorruptor:
elif aug == 'jpeg-medium': elif aug == 'jpeg-medium':
lo=23 lo=23
range=25 range=25
elif aug == 'jpeg-broad':
lo=10
range=60
# JPEG compression # JPEG compression
qf = (rand_int % range + lo) qf = (rand_int % range + lo)
# cv2's jpeg compression is "odd". It introduces artifacts. Use PIL instead. # cv2's jpeg compression is "odd". It introduces artifacts. Use PIL instead.