Olá a todos,estou com um problema para equalizar um histograma. Uso o programa processing. O erro é o seguinte: ArrayIndexoutofBoundsException na linha 38. Já tentei de tudo,mas nada dá certo. Obrigado.
size(600,466);
PImage img = loadImage("tank2.jpg");
//PImage img2 = createImage(img.width,img.height,RGB);
image(img , 0 ,0);
int[] hist = new int[256];
int cont = 0;
for (int i=0;i<img.width;i++){
for (int j =0; j<img.height;j++){
int bright = int(brightness(get(i,j)));
hist[bright]++;
cont+=1;
}
}
int histMax = max(hist);
stroke(255);
for (int i=0; i<img.width; i+=2){
int which = int(map(i,0,img.width,0,255));
int y= int(map(hist[which],0,histMax,img.height,0));
line(i,img.height,i,y);
}
//print (cont);
//Calcula o comulativo
for (int j=1;j < hist.length; j++){
hist[j] = hist[j] + hist[j-1];
}
int num = 255 / cont; /*alpha = 255 / numPixels
for each pixel Equação para calcular equalização do histograma.
g(x,y) = cumulativeFrequency[f(x,y)] * alpha
end for*/
//Equalizar o histograma
for (int v = 0; v < img.height; v++){
for (int u = 0; u < img.width; u++){
int c = get(v,u);
int d = hist[c] * num; //ArrayIndexoutofBoundsException
img.set(u,v,d);
}
}
print(hist.length);
image(img,0,0);