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
|
private int[] dec(int rgb){
return new int[] {rgb & 0xFF, (rgb & 0XFF00)>>8, (rgb & 0XFF0000)>>16};
}
private int comp(int[] rgb){
return rgb[0]+(rgb[1]<<8) + (rgb[2]<<16);
}
private int[] applyMatrix(float[][] matrice, int[][][] points){
double[] temp = new double[] {0.0d,0.0d,0.0d};
for (int line = 0; line < matrice.length){
matriceLine = matrice[line];
int[][] pointLine points[line];
for (int col = 0; col < matriceLine.length; col++){
float poids = matriceLine[col];
int[] point = pointLine[col];
for (int i = 0; i<3;i++){
temp[i]+=float*point[i];
}
}
}
return new int[] {
Math.max(0,Math.min(255,(int)temp[0])),
Math.max(0,Math.min(255,(int)temp[1])),
Math.max(0,Math.min(255,(int)temp[2])),
};
}
int[][][] points = {
{dec(img.getRGB(i-1, j-1)),dec(img.getRGB(i, j-1)),dec(img.getRGB(i+1, j-1))},
{dec(img.getRGB(i-1, j)) ,dec(img.getRGB(i, j)) ,dec(img.getRGB(i+1, j))},
{dec(img.getRGB(i-1, j+1)),dec(img.getRGB(i, j+1)),dec(img.getRGB(i+1, j+1))}
}
int[] result = applyMatrix(convolve,points);
res.setRgb(comp(result); |
Partager