【发布时间】:2017-10-26 04:05:59
【问题描述】:
我正在尝试用 Java 对灰度图像进行直方图均衡化。描述如下: 使用每个像素的RGB的一个波段作为查找表的索引,对图像进行迭代,以确定图像的新像素值。将每个像素的RGB设置为新像素值对应的RGB。
实现这一点后,我得到了一张蓝色的图像:
[已删除]
(预期结果)
[已删除]
这是我目前的代码:
private void histogramEqualize(BufferedImage im, int[] lut) {
for (int x = 0; x < im.getWidth(); x++) {
for (int y = 0; y < im.getHeight(); y++) {
Color c = new Color(im.getRGB(x, y));
Color eq = new Color(lut[c.getRed()], c.getGreen(), c.getBlue());
im1.setRGB(x, y, eq.getRGB());
}
}
}
public int[] getLookupTable(int[] h, int n) {
// h: Histogram for im1 in either the red band or luminance.
lut = new int[256];
double sf = 255/n;
int sumH = 0;
int sk = 0;
for(int i=0; i<h.length; i++) {
sumH += h[i];
sk = (int)(sf*sumH);
lut[i] = sk;
}
return lut;
}
我也尝试将Color eq = new Color(lut[c.getRed()], c.getGreen(), c.getBlue()); 更改为Color eq = new Color(lut[c.getRed()], lut[c.getGreen()], lut[c.getBlue()]);,但这导致图像为黑色。
【问题讨论】:
标签: java image-processing histogram