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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
package jwebcam;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.text.DecimalFormat;
public class Comparaison extends Thread{
protected BufferedImage Cap = null;
protected BufferedImage Ref = null;
protected HSB[] TabCap = null;
protected HSB[] TabRef = null;
protected int width, height = 0;
public Comparaison (Image image){
this.Ref = ImagetoBufferedImage(new ImageIcon("reference.jpg").getImage());
this.Cap = ImagetoBufferedImage(image);
this.width = Cap.getWidth(null);
this.height = Cap.getHeight(null);
TabCap = new HSB[width*height];
TabRef = new HSB[width*height];
}
/**convertie une Image en BufferedImage*/
public BufferedImage ImagetoBufferedImage(Image img){
if( img instanceof BufferedImage)
return (BufferedImage)img;
else{
BufferedImage BI =new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics g= BI.createGraphics();
g.drawImage(img,0,0,null);
g.dispose();
return BI;
}
}
/**détermine les 3 couleurs rouge vert bleu et les transforme
* en leur composante HSB
*/
public HSB[] luminosité(int[] tabPix){
int vert = 0, bleu = 0, rouge = 0;
Color couleur = new Color(rouge,vert,bleu);
float[] tab = new float[3];
int pix=0;
HSB[] tabResult = new HSB[width*height];
for (int i = 0; i < width * height; i++) {
pix = tabPix[i];
bleu = pix & 0xff;
vert = (pix >> 8) & 0xff;
rouge =(pix >> 16) & 0xff;
couleur.RGBtoHSB(rouge,vert,bleu,tab);
tabResult[i] = new HSB(tab[0],tab[1],tab[2]);
}
return tabResult;
}
/**récupère la valeur de la composante RGB de chaque pixels*/
public int[] RGBPixel(BufferedImage BI, int x, int y, int width, int height) {
int tab[] = new int[width * height];
BI.getRGB(x, y, width, height, tab, 0, width);
return tab;
}
/**traçage de l'ISO_LUX*/
public double[] ISO(HSB[] tabResult){
int z = 0,x = 0, y = 0,d=0;
double cptL1=0, cptL2=0, cptL3=0, cptL4=0, cptL5=0, cptL6=0, cptL7=0, cptL8=0, cptL9=0, cptL10=0, TotalPixels=0;
double h=1.0;
double[] tab = new double[10];
//MesCouleur cool= new MesCouleur();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if ( (tabResult[z].getLum()) >= 0.98 && tabResult[z].getLum()<= 1.0){
this.Cap.setRGB(y, x, Color.HSBtoRGB( (float) 0.00, (float) 1.0, (float) 0.75));
tab[0]=cptL1++;
}
if ( (tabResult[z].getLum()) >= 0.90 && tabResult[z].getLum() < 0.98){
this.Cap.setRGB(y, x, Color.HSBtoRGB( (float) 0.09, (float) 1.0, (float) 0.85));
tab[1]=cptL2++;
}
if ( (tabResult[z].getLum()) >= 0.80 && tabResult[z].getLum() < 0.90){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.15,(float)1.0,(float)0.85));
tab[2]=cptL3++;
}
if ( (tabResult[z].getLum()) >= 0.70 && tabResult[z].getLum() < 0.80){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.21,(float)1.0,(float)0.75));
tab[3]=cptL4++;
}
if ( (tabResult[z].getLum()) >= 0.60 && tabResult[z].getLum() < 0.70){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.27,(float)1.0,(float)0.65));
tab[4]=cptL5++;
}
if ( (tabResult[z].getLum()) >= 0.50 && tabResult[z].getLum() < 0.60){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.45,(float)1.0,(float)0.75));
tab[5]=cptL6++;
}
if ( (tabResult[z].getLum()) >= 0.40 && tabResult[z].getLum() < 0.50){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.57,(float)1.0,(float)0.75));
tab[6]=cptL7++;
}
if ( (tabResult[z].getLum()) >= 0.30 && tabResult[z].getLum() < 0.40){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.66,(float)1.0,(float)0.75));
tab[7]=cptL8++;
}
if ( (tabResult[z].getLum()) >= 0.20 && tabResult[z].getLum() < 0.30){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.77,(float)1.0,(float)0.75));
tab[8]=cptL9++;
}
if ( (tabResult[z].getLum()) >= 0.00 && tabResult[z].getLum() < 0.20){
this.Cap.setRGB(y, x, Color.HSBtoRGB((float)0.83,(float)1.0,(float)0.25));
tab[9]=cptL10++;
}
/*if((tabResult[z].getLum()==1.0) && (tabResult[z].getSat()==0.00) && (tabResult[z].getTeinte()==0.00)){
tabC[d++] = new centre(y,x);
//this.BI.setRGB(y, x, 16777215);
}*/
y++;
z++;
h=1.0;
}
y = 0;
x++;
}
//saveJPEG("D:\\JBuilder\\travail\\JWebCam\\capture.jpg");
return tab;
}
public void CalculePourcen(double[] tab1, double[] tab2){
MonPourcentage Pour = new MonPourcentage();
DecimalFormat df = new DecimalFormat("#0.##");
if (Pour.jCheckBox1.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[0] * 100) / tab2[0])));
}
if (Pour.jCheckBox2.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[1] * 100) / tab2[1])));
}
if (Pour.jCheckBox3.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[2] * 100) / tab2[2])));
}
if (Pour.jCheckBox4.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[3] * 100) / tab2[3])));
}
if (Pour.jCheckBox5.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[4] * 100) / tab2[4])));
}
if (Pour.jCheckBox6.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[5] * 100) / tab2[5])));
}
if (Pour.jCheckBox7.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[6] * 100) / tab2[6])));
}
if (Pour.jCheckBox8.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[7] * 100) / tab2[7])));
}
if (Pour.jCheckBox9.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[8] * 100) / tab2[8])));
}
if (Pour.jCheckBox10.isSelected() == false) {}
else {
Pour.jLabel1.setText("" + (df.format( (tab1[9] * 100) / tab2[9])));
}
Pour.pack();
}
/**thread de traitement*/
public void run() {
int tabLum[] = new int[width*height];
int tabLum2[] = new int[width*height];
double tab1[] = new double[10];
double tab2[] = new double[10];
tabLum=RGBPixel(Cap,0, 0, width, height);
TabCap=luminosité(tabLum);
tab1=ISO(TabCap);
tabLum2=RGBPixel(Ref,0, 0, width, height);
TabRef=luminosité(tabLum2);
tab2=ISO(TabRef);
CalculePourcen(tab1,tab2);
}
} |
Partager