1
votes

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?

1
Can you show us any code you've written so far that talks about the steps you completed? Also, if you use each combination of RGB values as a single bin in your histogram, you will not be able to store this histogram in memory because you will require an array of 256^3 x 64 bytes (assuming integer), and unfortunately this is too fine to have any discriminative power. It's best if you quantize the bins before computing the histogram.rayryeng

1 Answers

3
votes

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); 
                }
            }