- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGreenImageProcesser.java
More file actions
Latest commit
135 lines (128 loc) · 3.64 KB
/
Copy pathGreenImageProcesser.java
File metadata and controls
135 lines (128 loc) · 3.64 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
packageprocessing;
importjava.awt.Color;
importjava.awt.image.BufferedImage;
/**
* This class has the process method that process the image
* so that makes OUTSTANDING green color pixel into a 1
* and everything else into a 0
*
* @author jialuo
*
*/
publicclassGreenImageProcesser {
privatefloatredIndex;
privatefloatblueIndex;
privatefloatgreenIndex;
privatedoubleupperBound;
/**
* Construction method
*/
publicGreenImageProcesser(){
redIndex = -.45f;
greenIndex= 1.0f;
blueIndex= -.45f;
upperBound= 0.6;
}
/**
* Construction method
* @param redIndex : multiplier of red color value, domain from 0f to -1f
* recommended input: -0.2f to -0.4f for bright camera
* -0.4f to -0.7f for dim camera
* -0.7f to -0.9f for very dim camera
* @param greenIndex : multiplier of green color value, domain from 0f to 1f
* recommended input: 1f
* @param blueIndex : multiplier of red color value, domain from 0f to -1f
* recommended input: same as red
* @param upperBound : remove all point that values below this bound
* recommended input: for input G/R of -0.2 to -0.4f : 0.7 to 0.9
* for input G/R of -0.4f to -0.7f : 0.4 to 0.7
* for input G/R of -0.7f to -0.9f : 0.1 to 0.4
*/
publicGreenImageProcesser(floatredIndex,floatgreenIndex,floatblueIndex,doubleupperBound)
{
this.redIndex=redIndex;
this.greenIndex=greenIndex;
this.blueIndex=blueIndex;
this.upperBound=upperBound;
}
publicfloatgetRedIndex() {
returnredIndex;
}
publicvoidsetRedIndex(floatredIndex) {
this.redIndex = redIndex;
}
publicfloatgetBlueIndex() {
returnblueIndex;
}
publicvoidsetBlueIndex(floatblueIndex) {
this.blueIndex = blueIndex;
}
publicfloatgetGreenIndex() {
returngreenIndex;
}
publicvoidsetGreenIndex(floatgreenIndex) {
this.greenIndex = greenIndex;
}
publicdoublegetUpperBound() {
returnupperBound;
}
publicvoidsetUpperBound(doubleupperBound) {
this.upperBound = upperBound;
}
/**
* The process method makes OUTSTANDING green color pixel into
* a 1 and everything else into a 0
*
* @param image: input BufferedImage that needed to be processed
* @return a float 2D array that contains only 1 and 0
* */
publicfloat[][] process(BufferedImageimage)
{
Color[][] asColors=newColor[image.getWidth()][image.getHeight()];
for (inty=0; y<asColors[0].length; y++) {
for (intx=0; x<asColors.length; x++) {
asColors[x][y]=newColor(image.getRGB(x, y));
}
}
float[][] luminance=ImageProcessor.luminance(asColors, redIndex, greenIndex, blueIndex); //phone(-.3,1,-.3)
ImageProcessor.normalize(luminance);
float [][] contrastedData=newfloat[luminance.length][luminance[0].length];
for(inty=0;y<luminance[0].length;y++)
{
for(intx=0; x<luminance.length;x++)
{
if (luminance[x][y]>upperBound)
{
contrastedData[x][y]=1;
}
else
{
contrastedData[x][y]=0;
}
}
}
float [][]modifiedData=newfloat [luminance.length][luminance[0].length];
intvalidMinimum=5;
for(inty=2;y<luminance[0].length-2;y++)
{
for(intx=2; x<luminance.length-2;x++)
{
intcounter=0;
for(inti=0;i<3;i++)
{
for(intj=0;j<3;j++)
counter+=contrastedData[x-1+i][y-1+i];
if(counter>validMinimum)
{
modifiedData[x][y]=1;
}
else
{
modifiedData[x][y]=0;
}
}
}
}
returnmodifiedData;
}
}