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
| public double[] getRGBtoHSB(){
// Recuperation des valeurs RGB du pixel
//
//Transformation en valeur XYZ
//
//X= 0.49*R +0.31*G + 0.2*B
//Y= 0.17697*R + 0.81240*G + 0.01063*B
//Z= 0.01*G + 0.99*B
//
//Transformation en valeur chromatique
//x=X/(X+ Y+ Z)
//y=Y/(X+ Y+ Z)
//z=Z/(X+ Y+ Z)
int[] RGB = getDominante();
double[] XYZ = new double[3];
double[] xyz = new double[3];
XYZ[0]=0.49*RGB[0] +0.31*RGB[1] + 0.2*RGB[2];
XYZ[1]=0.17697*RGB[0] + 0.81240*RGB[1] + 0.01063*RGB[2];
XYZ[2]=0.01*RGB[1] + 0.99*RGB[2];
double coef = (XYZ[0]+ XYZ[1]+ XYZ[2]);
xyz[0] =XYZ[0]/coef;
xyz[1] =XYZ[1]/coef;
xyz[2] =XYZ[2]/coef;
return xyz;
}
public Double distanceCouleurHSB(Image testImg){
//saturation
//image.getImage().getGraphics().getColor().getHSBColor(h, s, b)
//
//Calculer de la Distance euclydienne
//
//D=srt( (x - xref) *(x - xref) + (y-yref)*(y-yref))
//
//
//Comparaison des distances genre
//
//si (D < DMax)
//les couleurs se correspondent ....
Double d = Double.parseDouble("-1");
double[] xyz= getRGBtoHSB();
double[] xyz2 = testImg.getRGBtoHSB();
d = Math.sqrt(Math.pow((xyz[0]-xyz2[0]),2)+Math.pow((xyz[1]-xyz2[1]),2)+Math.pow((xyz[2]-xyz2[2]),2));
return d;
}
public Double distanceCouleurRGB(Image testImg){
// couleur1(R1G1B1) **couleur2(R2G2B2)
//distnace entre couleur1 et 2=RacineCarre( (R1-R2)²+(G1-G2)²+(B1-B2)² ***)
Double d = Double.parseDouble("-1");
int[] RGB = getDominante();
int[] RGB2 = testImg.getDominante();
d = Math.sqrt(Math.pow((RGB[0]-RGB2[0]),2)+Math.pow((RGB[1]-RGB2[1]),2)+Math.pow((RGB[2]-RGB2[2]),2));
return d;
} |