-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR.py
86 lines (65 loc) · 1.57 KB
/
IR.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
72
73
74
75
76
77
78
79
80
81
82
IR = "river.jpg"
IB = "river.jpg"
NIVDTest = "river.jpg"
def openImage(pic, winnum):
IR = pmOpenImage(winnum,pic)
wd = getWidth(winnum)
ht = getHeight(winnum)
def getWidth(n):
width = pmGetImageWidth(n)
return width
def getHeight(n):
height = pmGetImageHeight(n)
return height
#because of our camera, the red channel is mostly just ir
#so we will use that to compute our ir image
def NIR(pic,winnum):
wd = getWidth(winnum)
ht = getHeight(winnum)
print wd
print ht
print "this is rgb for 200 100"
print pmGetPixel(winnum,200,100)
for w in range(wd):
for h in range(ht):
rgb = pmGetPixel(winnum,w,h)
red = rgb[0]
rgb = pmSetPixel(winnum,w,h, red, red, red)
def NIB(pic ,winnum):
wd = getWidth(winnum)
ht = getHeight(winnum)
for w in range(wd):
for h in range(ht):
rgb = pmGetPixel(winnum,w,h)
blue = rgb[2]
rgb = pmSetPixel(winnum,w,h, blue, blue, blue)
def NIVD(pic, winnum):
wd = getWidth(winnum)
ht = getHeight(winnum)
for w in range(wd):
for h in range(ht):
rgb = pmGetPixel(winnum,w,h)
compared = compare(rgb[0], rgb[1], rgb[2])
rgb = pmSetPixel(winnum,w,h, compared[0], compared[1], compared[2] )
def compare(red, green, blue):
bsubr = blue-red
gsubr = green-red
if(red>blue):
green += bsubr
blue = 0
red = 0
elif(blue<red):
red /=4
blue += (gsubr+red)
green = 0
return(red, green, blue)
pmOpenImage(0,"river.jpg")
#pmOpenImage(1, "riverbluehst.jpg")
openImage(IR, 1)
openImage(IB, 2)
openImage(NIVDTest, 3)
NIR(IR,1)
NIB(IB,2)
NIVD(NIVDTest,3)
#pmOpenImage(5, "nir_river.jpg")
#pmOpenImage(4, "blue_river.jpg")