直方图使用查找表对图像进行均衡

时间:2017-10-26 04:06:00

标签: java image-processing histogram

我试图在Java中用直方图均衡灰度图像。描述如下:使用每个像素的RGB的一个带作为查找表的索引来迭代图像,以确定图像的新像素值。将每个像素的RGB设置为与新像素值对应的RGB。

实现这个我得到一个蓝色的图像:

[移除]

(预期结果)

[移除]

这是我到目前为止的代码:

const multiplyBy10 = (x) => 10 * x; 
console.log(multiplyBy10(5));

我也尝试将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());,但这会产生黑色图像。

1 个答案:

答案 0 :(得分:0)

您已经提到要在灰度图像上应用直方图均衡,但是您使用的是像素的RGB颜色值。

对于灰度图像,您可以仅对图像中的灰度等级进行标准化,以进行直方图均衡,如下所示:

1)迭代每个灰度像素值,并通过计算它们在图像中的出现次数来生成每个灰度级的直方图数据。

2)找出上述直方图的累积分布。

3)迭代原始图像中的每个灰度像素值,并使用下面的公式将它们的值替换为它们对应的标准化值。 histogram equalization formula

 where L=255, that is total gray scale levels,
 M = Image height,
 N = Image width,
 MxN to get total number of pixels in image.
 cdfmin = min value of cumulative distribution data in step 2.

这将为您提供新的标准化图像矩阵。

如果要在RGB图像上应用直方图均衡,则需要将RGB颜色空间转换为HSV颜色空间,并在值通道上应用与灰度图像相同的步骤,而不更改其色调和饱和度值。

相关问题