5

I've been trying to figure out the algorithm to perform full adaptive histogram equalization (without interpolating). However, I still seem to be missing a piece and haven't managed to get the result image right.

Here are the steps that I followed, hoping somebody could shed some light on what is missing:

  1. Input a gray scale image (0-255).
  2. Creating an over-sized image and mirroring the values near the borders to avoid borders and corners special cases. (As proposed in page 20 in this article: Adaptive Histogram Equalization a Parallel Implementation)
  3. Initialize a rank 0 for each pixel in the source image.
  4. For each pixel in the source image, find its rank in its local area (local area size will be given as input). Pixel rank is the number of pixels in the local area that are smaller than the center pixel (The pixel we are looping on, in the source image)
  5. New pixel value calculated by: Rank * (Maximum intensity = 255) / (Number of pixels in local area)

Following these steps result in the following output for 30x30 local area window size:

Original:

Original

Output:

Output

I'm hoping for some guidance in the following matter as to what I'm missing here.

Sandipan Dey
  • 21,482
  • 2
  • 51
  • 63
Elia
  • 762
  • 1
  • 12
  • 28
  • As I was going to add part of the code here, I tried it one last time on new test image, and it worked. The problem was that the image above, had 2 lines of gray pixels that shouldn't have been there (Got the image using snipping tool, must have clipped some of the outside border with it). The algorithm above works perfectly. – Elia Mar 17 '15 at 13:39
  • Would it be possible for you to post some code for your implementation. I am trying to do something similar and I seem to have hit a dead end trying to slice my images. – user2808264 Apr 19 '17 at 00:07
  • I am trying to do something similar. Would it be possible for you to make some suggestions. I have posted my question at http://stackoverflow.com/questions/43580776/parallel-implementation-of-adaptive-histogram-equalization – user2808264 Apr 24 '17 at 07:10

1 Answers1

2

We can implement the above AHE algorithm with the following python code, for a parallelized version refer to this thesis. Here wsz is the context window size parameter:

def AHE(im, wsz=8):    
    h, w = im.shape
    out = np.zeros(im.shape) # Declare output variable
    im = np.pad(im.copy(), ((wsz//2, wsz//2), (wsz//2, wsz//2)), mode = 'reflect')
    for x in range(wsz//2, h + wsz//2):
        for y in range(wsz//2, w + wsz//2):
            blk = im[x-wsz//2:x+wsz//2, y-wsz//2:y+wsz//2]
            rank = np.sum(im[x, y] > blk)
            out[x - wsz//2, y - wsz//2] = rank * 255 / wsz**2
    return out

and obtain the following output (with wsz=50):

enter image description here

Sandipan Dey
  • 21,482
  • 2
  • 51
  • 63