def augment(images):
pixels = images[0].shape[1]
center = pixels/2.-0.5
random_flip_x = FLIP_X and np.random.randint(2) == 1
random_flip_y = FLIP_Y and np.random.randint(2) == 1
# Translation shift
shift_x = np.random.uniform(*TRANS_RANGE)
shift_y = np.random.uniform(*TRANS_RANGE)
rotation_degrees = np.random.uniform(*ROT_RANGE)
zoom_factor = np.random.uniform(*ZOOM_RANGE)
#zoom_factor = 1 + (zoom_f/2-zoom_f*np.random.random())
if CV2_AVAILABLE:
M = cv2.getRotationMatrix2D((center, center), rotation_degrees, zoom_factor)
M[0, 2] += shift_x
M[1, 2] += shift_y
for i in range(len(images)):
image = images[i]
if random_flip_x:
image[:,:] = image[:,::-1,]
if random_flip_y:
image = image.transpose(1,0)
image[:,:] = image[::-1,:]
image = image.transpose(1,0)
if i==0: # lung
rotate(image, rotation_degrees, reshape=False, output=image, cval=-3000)
else:# truth and outside
rotate(image, rotation_degrees, reshape=False, output=image)
#image2 = zoom(image, [zoom_factor,zoom_factor])
image2 = crop_or_pad(image, pixels, -3000)
shift(image2, [shift_x,shift_y], output=image)
images[i] = image
return images
评论列表
文章目录