-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimageaugmentation.py
38 lines (29 loc) · 1.28 KB
/
imageaugmentation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import cv2
import imgaug.augmenters as iaa
# Define the augmentation techniques you want to apply
seq = iaa.Sequential([
iaa.Fliplr(0.5), # flip horizontally with a probability of 0.5
iaa.GaussianBlur(sigma=(0, 3.0)), # add Gaussian blur with sigma between 0 and 3.0
iaa.Affine(rotate=(-45, 45)) # rotate between -45 and 45 degrees
])
# Define the input folder
input_folder = 'Data/No Pnuemothorax'
# Loop through all images in the input folder
for filename in os.listdir(input_folder):
# Load the image
img = cv2.imread(os.path.join(input_folder, filename))
# Apply the augmentation sequence to the image
augmented_img = seq(image=img)
# Save the augmented image to the same folder with a modified filename
cv2.imwrite(os.path.join(input_folder, 'aug_' + filename), augmented_img)
# Define the input folder
input_folder = 'Data/Pnuemothorax'
# Loop through all images in the input folder
for filename in os.listdir(input_folder):
# Load the image
img = cv2.imread(os.path.join(input_folder, filename))
# Apply the augmentation sequence to the image
augmented_img = seq(image=img)
# Save the augmented image to the same folder with a modified filename
cv2.imwrite(os.path.join(input_folder, 'aug_' + filename), augmented_img)