-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.java
142 lines (116 loc) · 4.32 KB
/
process.java
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
136
137
138
139
140
141
142
package train;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
public class process {
public process(){
}
double[][][] skin = new double[256][256][256];
double[][][] nonskin=new double[256][256][256];
public void initialArray(){
for(int i=0;i<256;i++){
for(int j=0;j<256;j++){
for(int k=0;k<256;k++){
skin[i][j][k]=0;
nonskin[i][j][k]=0;
}
}
}
}
public void training(String[] images,String[] masks,int k){
System.out.println(k);
System.out.println(images[k]);
System.out.println(masks[k]);
File mainImage=new File(images[k]);
File maskImage=new File(masks[k]);
BufferedImage mainpic=null;
BufferedImage maskpic=null;
try {
mainpic= ImageIO.read(mainImage);
maskpic= ImageIO.read(maskImage);
int r,g,b;
for(int i=0;i<mainpic.getHeight();i++){
for(int j=0;j<mainpic.getWidth();j++){
Color mainpiccolor=new Color(mainpic.getRGB(j,i));
Color maskpiccolor=new Color(maskpic.getRGB(j,i));
r=mainpiccolor.getRed();
g=mainpiccolor.getGreen();
b=mainpiccolor.getBlue();
// System.out.println(maskpic.getRGB(j,i));
if(maskpiccolor.getRed()>=255 && maskpiccolor.getGreen()>=255 && maskpiccolor.getBlue()>=255){
// System.out.println("it is non skin");
nonskin[r][g][b]++;
}
else{
// System.out.println("it is skin");
skin[r][g][b]++;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void determineImage(String[] images,String[] masks,int p){
int cout = 0;
if(p==5){
cout=100;
}
for(int k=cout;k<(images.length/5)*p;k++){
training(images,masks,k);
}
for(int k=(images.length/5)*p+(images.length/5);k<images.length;k++){
training(images,masks,k);
}
}
public void minedata(String[] images,String[] masks,int p) throws IOException {
initialArray();
determineImage(images,masks,p);
double totalskincount=0;
double totalnonskincount=0;
for(int i=0;i<256;i++){
for(int j=0;j<256;j++){
for(int k=0;k<256;k++){
totalskincount=skin[i][j][k]+totalskincount;
totalnonskincount=nonskin[i][j][k]+totalnonskincount;
}
}
}
System.out.println(totalskincount);
System.out.println(totalnonskincount);
double[][][] keepresult=new double[256][256][256];
BufferedWriter mainBW = new BufferedWriter(new FileWriter("knowledge.dat"));
mainBW.write("");
for(int i=0;i<256;i++){
for(int j=0;j<256;j++){
for(int k=0;k<256;k++){
/* if(nonskin[i][j][k]==0)
{
keepresult[i][j][k]=100;
}
else
{
keepresult[i][j][k]=(skin[i][j][k]/totalskincount)/(nonskin[i][j][k]/totalnonskincount);
}
*/
nonskin[i][j][k]=nonskin[i][j][k]/totalnonskincount;
skin[i][j][k]=skin[i][j][k]/totalskincount;
if(nonskin[i][j][k]==0 && skin[i][j][k]>0) keepresult[i][j][k]=100;
else if(nonskin[i][j][k]==0 && skin[i][j][k]==0) keepresult[i][j][k]=0;
else {
keepresult[i][j][k]=skin[i][j][k]/nonskin[i][j][k];
}
//System.out.println(String.format("%.3f\n", keepresult[i][j][k]));
mainBW.append(String.format("%.3f\n", keepresult[i][j][k]));
}
}
}
mainBW.close();
System.out.println("Successful");
}
}