# main idea of Adaptive histogram equalization (AHE)

I want to understand the main idea behind AHE and the way for applying it manually with my hands.

Wikipedia says:

In its simplest form, each pixel is transformed based on the histogram of a square surrounding the pixel, as in the figure below. The derivation of the transformation functions from the histograms is exactly the same as for ordinary histogram equalization: The transformation function is proportional to the cumulative distribution function (CDF) of pixel values in the neighbourhood.

Does above mean for computing AHE we divide the matrix into distinct squares and do HE on each square separately?

In this basic form the method involves applying to each pixel the histogram equalization mapping based on the pixels in a region surrounding that pixel (its contextual region). That is, each pixel is mapped to an intensity proportional to its rank in the pixels surrounding it.

Does it again says what I quoted from Wikipedia? Does "its rank in the pixels surrounding it" mean applying the usual HE?

J. Alex Stark says:

The AHE process can be understood in different ways. In one perspective the histogram of grey levels (GL’s) in a window around each pixel is generated first. The cumulative distribution of GL’s, that is the cumulative sum over the histogram, is used to map the input pixel GL’s to output GL’s. If a pixel has a GL lower than all others in the surrounding window the output is maximally black; if it has the median value in its window the output is 50% grey.

It seems this one differs from what I quoted earlier. I think it says for each pixel we have to consider a square around it and first apply the usual HE and store the result in another temp matrix, then compare the intensity of center pixel with intensities of other pixels in temp matrix and decide the output of AHE for center pixel is 50% gray or black. If it is true, then the output most only has two colors: black and 50% gray and no white pixel!

Now I have other questions:

• Do I understand above ways?
• Are those same or different ways?
• Are all of them AHE?
• Is there a formula for size of squares for dividing image? (OpenCV uses 8 as default)
• For getting the output of each pixel, do I have to consider a square around desired pixel or I have to divide image into distinct squares and get the output for all pixels of each square at once?
• If above quotes guide to different AHE s, then do all improve the problem of HE?

Edit1
After I asked this question I continue searching and found this which I think partially clear what I doubted from what had saied J. Alex Stark.

Edit2
Gonzalez in pages 149,150 of Digital Image Processing, Global Edition says:

The procedure is to deﬁne a neighborhood and move its center from pixel to pixel in a horizontal or vertical direction. At each location, the histogram of the points in the neighborhood is computed, and either a histogram equalization or histogram speciﬁcation transformation function is obtained. This function is used to map the intensity of the pixel centered in the neighborhood. The center of the neighborhood is then moved to an adjacent pixel location and the procedure is repeated. ... Another approach used sometimes to reduce computation is to utilize nonoverlapping regions, but this method usually produces an undesirable “blocky” effect.

• Jan 2 at 12:59

Does above mean for computing AHE we divide the matrix into distinct squares and do HE on each square separately?

Yes.

Does it again says what I quoted from Wikipedia?

Yes.

Does "its rank in the pixels surrounding it" mean applying the usual HE?

Yes.

I think it says for each pixel we have to consider a square around it and first apply the usual HE ...

Yes.

and store the result in another temp matrix, then compare the intensity of center pixel with intensities of other pixels in temp matrix and decide the output of AHE for center pixel is 50% gray or black.

No.

It's just saying the same as the previous ones: check where the current pixel's level is with respect to all the others in its region ("adaptive area").

The comparison is just done against the original image's pixel intensities.

For getting the output of each pixel, do I have to consider a square around desired pixel or I have to divide image into distinct squares and get the output for all pixels of each square at once?

The square is always centered around each pixel in turn.

Is there a formula for size of squares for dividing image? (OpenCV uses 8 as default)

I don't think there's really a way to calculate it. It really depends on the type of image you're using and the resolution of the objects in the image.

• Thank you for your time. I edited my question. Please see it. I think there are different ways for doing local histogram equalization. What is your opinion? Jan 1 at 21:28
• Also what about this: Is there a formula for size of squares for dividing image? Jan 1 at 21:29
• @hasanghaforian That new link just seems to want to calculate the AHE quickly. If it changes the algorithm, then it's no longer AHE.
– Peter K.
Jan 1 at 21:54
• It seems that you say only usual HE on smaller parts of image and anything else is not AHE. Also in your answer you wrote "check where the current pixel's level is with respect to all the others in its region ("adaptive area").". We know that this check is not part of usual HE so, as you said, it should not effect on output of HE. If this "check" has no effect on output, why is it necessary? Jan 1 at 22:47
• @hasanghaforian The check is definitely part of the usual HE, it’s just that the usual HE uses the whole image as the check area, not a subset of the image.
– Peter K.
Jan 1 at 23:23