//获取图像的直方图
int[] histogram = new int[256];
for(int i=0; i<ih*iw; i++){
int grey = pixels[i]&0xff;
histogram[grey]++;
} //计算每一个灰度级的像素数
//直方图均衡化
double a = (double)255/(iw*ih);
double[] c = new double [256];
c[0] = (a*histogram[0]);
for(int i=1; i<256; i++){
c[i] = c[i-1]+(double)(a*histogram[i]);//直方图均衡化
}
for(int i=0; i<ih; i++){
for(int j=0; j<iw; j++){
int grey = pixels[i*iw+j]&0x0000ff;
int hist = (int)(c[grey]);
pixels[i*iw+j] = 255<<24|hist<<16|hist<<8|hist;
greyImage.setRGB(j, i, pixels[i*iw+j]);
}
}
tmp = greyImage;
flag_load = true;
repaint();
}else{
JOptionPane.showMessageDialog(null, "先点击“装载图像”,3Q!","提示:",
JOptionPane.WARNING_MESSAGE);
}
}
int[] histogram = new int[256];
for(int i=0; i<ih*iw; i++){
int grey = pixels[i]&0xff;
histogram[grey]++;
} //计算每一个灰度级的像素数
//直方图均衡化
double a = (double)255/(iw*ih);
double[] c = new double [256];
c[0] = (a*histogram[0]);
for(int i=1; i<256; i++){
c[i] = c[i-1]+(double)(a*histogram[i]);//直方图均衡化
}
for(int i=0; i<ih; i++){
for(int j=0; j<iw; j++){
int grey = pixels[i*iw+j]&0x0000ff;
int hist = (int)(c[grey]);
pixels[i*iw+j] = 255<<24|hist<<16|hist<<8|hist;
greyImage.setRGB(j, i, pixels[i*iw+j]);
}
}
tmp = greyImage;
flag_load = true;
repaint();
}else{
JOptionPane.showMessageDialog(null, "先点击“装载图像”,3Q!","提示:",
JOptionPane.WARNING_MESSAGE);
}
}