I wanna augment my grayscale images by rotating and flipping them. however, when I rotate them they get doubled. I don't know how to explain it so I've uploaded a sample image. you can see the image here
my code:
Load glioma images
train_glioma_img = []
for path in glioma_train_path:
img = imread(path)
if len(img.shape) > 2: # incase it has 3 dim __ making sure that all of the images are gray scale
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
image = np.array(img).astype(np.float64)
train_glioma_img.append(image)
else:
image = np.array(img).astype(np.float64)
train_glioma_img.append(image)
train_glioma_x = np.array(train_glioma_img)
train_glioma_x.shape
# Augment them
final_train_data = []
number_of_added_images = int((2000-len(glioma_train_path))/2)
a = random.sample(range(0, len(glioma_train_path)), number_of_added_images)
b = [i for i in range(0, len(glioma_train_path)) if i not in set(a)]
for i in tqdm(range(train_glioma_x.shape[0])):
final_train_data.append(train_glioma_x[i])
for i in tqdm(range(number_of_added_images)):
final_train_data.append(rotate(train_glioma_x[a[i]], angle=random.randint(20, 100), mode = 'wrap'))
for i in tqdm(range(number_of_added_images)):
final_train_data.append(np.fliplr(rotate(train_glioma_x[b[i]], angle=random.randint(20, 100), mode = 'wrap')))
To show single image
image = np.array(final_train_data[1990])
hi = np.max(image)
lo = np.min(image)
image = (((image - lo)/(hi-lo))*255).astype(np.uint8)
im = Image.fromarray(image)
im