The Histogram Equalization: Neighborhood Adaptive algorithm, a high-pass filter, enhances the contrast in an image by reevaluating the grayscale, or intensity, value of each pixel based on a region of nearby pixels.

## Contents

### Background

Features in some images require a larger range of intensity values than are displayed. Histogram equalization is a method to improve the contrast of an area in an image by shifting intensity values so that there are an equal number of pixels in an image in each intensity. This algorithm tabulates the histogram for a collection of neighboring pixels, sometimes called a kernel and then assigns the pixel to the new histogram level.

The name of this algorithm signifies that it processes the image by looking at the neighboring pixels when performing the equalization; hence, the name Neighborhood, or Local, Adaptive Histogram Equalization. Each neighborhood of pixels is the source when remapping the histogram, adapting the value of the pixel to its location in the histogram of the neighborhood.

The algorithm first collects a list of the pixel's neighbors, calculates the bin width of the pixel neighborhood, then builds the histogram of the neighborhood.

 bin width-The permitted range of floating-point values of a pixel to equate to an intensity level in a 256-color image.

The algorithm locates the value of the central pixel in the local histogram and replaces its intensity with the corresponding value in the histogram of its neighbors. The algorithm remaps the brightest pixel in a pixel neighborhood to the brightest value in the histogram (i.e., 256) and the darkest pixel to the lowest value of the histogram (i.e., 0), recording the new values as pixel-intensity values. It then processes each pixel in this way, remapping pixel value to intensity as measured against a histogram of the pixel's neighbors until the algorithm finishes checking all pixels of the image against the histogram of its neighbors and builds a new, or reference, image.
Performing histogram equalization makes it possible to see minor variations within portions of the reference image that appeared nearly uniform in the original, or source, image.

Arithmetically, the process in a neighborhood is rather simple: where Ni is the intensity of the i'th pixel, and T is the total number of pixels in the neighborhood.

Neighborhood size greatly affects the reference image, since the intensity of each resulting pixel depends on the neighborhood. The more pixels in the neighborhood that are darker than the current pixel, the greater in intensity the current pixel becomes in the reference image. Likewise, the shape of the kernel determines the number of pixels in the neighborhood.

The algorithm creates a kernel around a pixel in a region of the image as shown in Figure 1. It then ranks the intensity of that pixel as compared to the surrounding pixels. In the figure, the box is 65 pixels wide. Using a square kernel, the algorithm collects all the pixel intensities inside the square and at the edges of the square. (Using a cross kernel, however, it collects only the intensities under the orange cross-hairs.) It next ranks the pixel intensity at the center of the cross hairs against the histogram of the pixels in the kernel.

The reference image using the new histogram is similar to the source image; however, in areas where the original image had similar values, the reference image is enhanced. The output histogram now stretches over a greater proportion of the possible image intensities.

Figure 2 shows example images that were created by starting with a source image then using a 21 x 21, a 45 x 45, or 65 x 65 square kernel through the image.

The histogram of the source image is very compact in structure; that is, it has a great number of darker pixels, but very few brighter pixels. In fact, the bottom-most intensity values make up almost all of the pixels' values in the image. Note, however, in the histogram of the reference image, the look-up table is more evenly spread than in the histogram of the source image. Also, areas of low intensity and low contrast in the source image were correspondingly remapped in the reference image to areas of higher contrast and generally overall brighter values.

 Note: The red line at the border of the image is an active image line, a part of the program to help the user determine which image is on top and not a part of the image itself.  There are a couple of features to notice about the resultant images. First, the reference images contain a lot of noise. This noise results because the algorithm remapped the areas of the image with smooth features using a histogram used for features with great variation (such as the lung cavity in the example images). Second, notice that the algorithm remaps large areas of the same level of intensity values very high-intensity areas. This feature could be expected, is distracting when viewing the image, and is therefore a good reason to include a threshholding feature to prevent processing on a pixel when its intensity is too low.

The histogram equalization process can enforce certain characteristics about the image called clipping. As the algorithm processes the image, it counts out the number of pixels of a certain intensity. Clipping cuts that counting short; it stores the excess pixels of a particular intensity and redistributes that number equally among all intensities. For instance, if a particular intensity must be clipped at 100 and the count is 145, the algorithm redistributes 45 pixels to other brightnesses. It adds to the count of each intensity level an equal number of pixels if there are enough excess, but attempts to spread the excess over as many pixels as possible.

#### Image types

You can apply this algorithm to both color and black-and-white images.

#### Special notes

This algorithm can evaluate the entire image or only specified volumes of interest (VOIs).