-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGreenImageProcesser.java
More file actions
135 lines (128 loc) · 3.64 KB
/
GreenImageProcesser.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
package processing;
import java.awt.Color;
import java.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
*
*/
public class GreenImageProcesser {
private float redIndex;
private float blueIndex;
private float greenIndex;
private double upperBound;
/**
* Construction method
*/
public GreenImageProcesser(){
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
*/
public GreenImageProcesser(float redIndex,float greenIndex,float blueIndex,double upperBound)
{
this.redIndex=redIndex;
this.greenIndex=greenIndex;
this.blueIndex=blueIndex;
this.upperBound=upperBound;
}
public float getRedIndex() {
return redIndex;
}
public void setRedIndex(float redIndex) {
this.redIndex = redIndex;
}
public float getBlueIndex() {
return blueIndex;
}
public void setBlueIndex(float blueIndex) {
this.blueIndex = blueIndex;
}
public float getGreenIndex() {
return greenIndex;
}
public void setGreenIndex(float greenIndex) {
this.greenIndex = greenIndex;
}
public double getUpperBound() {
return upperBound;
}
public void setUpperBound(double upperBound) {
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
* */
public float[][] process(BufferedImage image)
{
Color[][] asColors=new Color[image.getWidth()][image.getHeight()];
for (int y=0; y<asColors[0].length; y++) {
for (int x=0; x<asColors.length; x++) {
asColors[x][y]=new Color(image.getRGB(x, y));
}
}
float[][] luminance=ImageProcessor.luminance(asColors, redIndex, greenIndex, blueIndex); //phone(-.3,1,-.3)
ImageProcessor.normalize(luminance);
float [][] contrastedData=new float[luminance.length][luminance[0].length];
for(int y=0;y<luminance[0].length;y++)
{
for(int x=0; x<luminance.length;x++)
{
if (luminance[x][y]>upperBound)
{
contrastedData[x][y]=1;
}
else
{
contrastedData[x][y]=0;
}
}
}
float [][]modifiedData=new float [luminance.length][luminance[0].length];
int validMinimum=5;
for(int y=2;y<luminance[0].length-2;y++)
{
for(int x=2; x<luminance.length-2;x++)
{
int counter=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
counter+=contrastedData[x-1+i][y-1+i];
if(counter>validMinimum)
{
modifiedData[x][y]=1;
}
else
{
modifiedData[x][y]=0;
}
}
}
}
return modifiedData;
}
}