This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
02_Prepare_Data.py
71 lines (59 loc) · 2 KB
/
02_Prepare_Data.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from PIL import Image
import os
try:
os.makedirs('data/colorEnhanced/train/NoFire')
os.makedirs('data/colorEnhanced/val/NoFire')
os.makedirs('data/colorEnhanced/train/Fire')
os.makedirs('data/colorEnhanced/val/Fire')
except:
print("folder already exist")
perc = .05
print("percent to change Fire", perc)
def colorEnhancedIm(fldrIn, fn, fldrOut, perc=-.04, type='png'):
path = fldrIn + fn
im = Image.open(path).convert('RGB')
# Split into 3 channels
r, g, b = im.split()
# Increase Reds
r = r.point(lambda i: i * (1+perc))
# Decrease Greens
g = g.point(lambda i: i * (1-perc))
# Recombine back to RGB image
result = Image.merge('RGB', (r, g, b))
result.save(f'{fldrOut}/{fn}')
im.close()
# cropIm(fldrIn, fn, fldrOut)
import glob
FireList = []
NoFireList = []
fldrIn = "data/synthetic/train/Fire/"
fldrOut = "data/colorEnhanced/train/Fire/"
for fire, fn in enumerate(glob.glob(fldrIn+"*.png")):
fn_trunc = fn.split('/')[-1]
FireList.append(fn_trunc)
colorEnhancedIm(fldrIn, fn_trunc, fldrOut, perc, 'png')
print("completed train set")
fldrIn = "data/synthetic/val/Fire/"
fldrOut = "data/colorEnhanced/val/Fire/"
for fire, fn in enumerate(glob.glob(fldrIn+"*.png")):
fn_trunc = fn.split('/')[-1]
FireList.append(fn_trunc)
colorEnhancedIm(fldrIn, fn_trunc, fldrOut, perc, 'png')
print("completed val set")
perc = -1 * perc
print("percent to change NoFire", perc)
fldrIn = "data/synthetic/train/NoFire/"
fldrOut = "data/colorEnhanced/train/NoFire"
for fire, fn in enumerate(glob.glob(fldrIn+"*.png")):
fn_trunc = fn.split('/')[-1]
FireList.append(fn_trunc)
colorEnhancedIm(fldrIn, fn_trunc, fldrOut, perc, 'png')
print("completed train set")
fldrIn = "data/synthetic/val/NoFire/"
fldrOut = "data/colorEnhanced/val/NoFire/"
for fire, fn in enumerate(glob.glob(fldrIn+"*.png")):
fn_trunc = fn.split('/')[-1]
FireList.append(fn_trunc)
colorEnhancedIm(fldrIn, fn_trunc, fldrOut, perc, 'png')
print("completed val set")
print("done")