Histogram equalization using java

I want to perform histogram equalization for an RGB image. For this , at first I generate the histogram using the following steps :

1)Map the intensity in the range [0,255] , by taking the gray value as val=img.getRGB(j, i) & 0xFF;

2)count the number of pixels corresponding to each intensity value(0-255)

3)Plot the histogram.

4)perform equalization

5)Now the problem I am concerned with is , to map to the RGB image corresponding to the equalized histogram. How do I do that? All are grayvalues .Any solution?


I did this once in Java. Input is a grayvalue buffered Image bi. Histogram of bi will be equalized. Here is the code.

            int width =bi.getWidth();
            int height =bi.getHeight();
            int anzpixel= width*height;
            int[] histogram = new int[255];
            int[] iarray = new int[1];
            int i =0;

            //read pixel intensities into histogram
            for (int x = 1; x < width; x++) {
                for (int y = 1; y < height; y++) {
                    int valueBefore=bi.getRaster().getPixel(x, y,iarray)[0];
                    histogram[valueBefore]++;
                }
            }

            int sum =0;
         // build a Lookup table LUT containing scale factor
            float[] lut = new float[anzpixel];
            for ( i=0; i < 255; ++i )
            {
                sum += histogram[i];
                lut[i] = sum * 255 / anzpixel;
            }

            // transform image using sum histogram as a Lookup table
            for (int x = 1; x < width; x++) {
                for (int y = 1; y < height; y++) {
                    int valueBefore=bi.getRaster().getPixel(x, y,iarray)[0];
                    int valueAfter= (int) lut[valueBefore];
                    iarray[0]=valueAfter;
                     bi.getRaster().setPixel(x, y, iarray); 
                }
            }
链接地址: http://www.djcxy.com/p/89774.html

上一篇: 如何在MATLAB中绘制/绘制2D图形中的图像强度

下一篇: 使用java直方图均衡