-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTech3.py
54 lines (27 loc) · 1.24 KB
/
Tech3.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from fastai.vision.all import *
# define data augmentation techniques using Fastai
aug_transforms = aug_transforms(rotation_range=40,
zoom=0.2,
flip_vert=True,
flip_horiz=True,
max_lighting=0.2,
max_warp=0.2,
p_affine=0.75,
p_lighting=0.75)
# define a function to apply data augmentation to an image using Fastai
def apply_augmentation(img_path, output_path, aug_transforms):
img = PILImage.create(img_path)
augmented_img = img.apply_tfms(aug_transforms)
augmented_img.save(output_path)
# apply data augmentation to input image using Fastai
apply_augmentation('cat.jpg', 'cat_augmented.jpg', aug_transforms)
# additional features
# load input image using Fastai
img = PILImage.create('cat.jpg')
# apply contrast stretching to the image using Fastai
stretched_img = img.stretch_contrast(0.1)
# apply gamma correction to the image using Fastai
gamma_img = img.apply_gamma(1.5)
# save the contrast stretched and gamma corrected images
stretched_img.save('cat_stretched.jpg')
gamma_img.save('cat_gamma.jpg')