|
Java Image processing API
|
Local Histogram Equalization |
A local histogram filter, used for enhancing the contrasts in an image |
LocalHistogramFilter |
LocalHistogramFilterColorTest |
LocalHistogramFilterIntensityTest |
IntroductionHistogram equalization is used for enhancing the contrasts in an intensity image. This normally works quite well for smaller images or images where almost all of the different intensity levels are represented. For these situations, a different version of histogram equalization could be useful. If you could do equalization over a portion of the image, too many intensity levels in the image would less affect you. Of if you need to enhance the contrast more than a global histogram equalizer can offer. However, this is very computer intensive, as you would need to compute a histogram for each pixel in the image. The workload will increase proportional with n to the power of 2, where n is the number of pixels. In order to do local histogram equalization, the user has to pass over the image represented by a two dimensional array of short ints. The user also has to choose a mask size, which describes the size of the portion of the image to equalize at a time. The mask size has to be an odd number, because only the centre pixel of the mask will be written to the new and equalized image. The equalization begins with the mask being cantered on the upper left pixel. A histogram will be calculated for all pixels covered by the mask. The pixel in the centre of the mask will then be written to the resulting image. The mask is then moved one pixel to the right and a new histogram be computed. This continues for each pixel of each row in the image. One of the tricks to lower the processing time is to reuse part of the previous histogram. In this implementation, we create a single dimension array with length equal to the number of possible intensity levels in the image. For an 8-bit greyscale image, the length would be 256. The elements in this array hold the number of pixels that have this value of intensity of the pixels inside the mask. Then when the mask is moved, you can just subtract the pixels that leave the mask and add the ones that enter. This way, the array will still represent the histogram of the pixels inside the mask, but we didn’t have to recreate the entire histogram. A full recreation of the histogram would require n^2 counts (n is equal to the length og width of the mask), where the smarter method only would require 2n counts. As a result, one only needs to calculate 2n/n^2 = 2/n * 100% of an image. As the mask size grows, the savings will too. A mask size of 101 x 101, one would only have to do 2 / 101 * 100% = 1,98 % of the work. A whooping 98% decrease in workload ! For more information about computation time, please refer to LocalHistogramFilter Documentation. Another trick deployed is to only calculate the resulting value of the centre pixel. There’s no need to calculate the entire resulting histogram equalized image within the mask, as only the centre pixel will be written to the resulting image..The savings will not be as great as the previous trick, but it adds to overall improvement of processing time. |
Example 1 |
This image consist of 256 1 pixel wide vertical lines. Each line has a different color, ranging from black to white. |
![]() |
We the apply local histogram equalizing with a 3x3 mask on the image, we see that almost the entire image has changed to the middle intensity level between black and white. The reason for this effect is that the histogram equalization tries to enhance all contrasts. However, the image consists of nothing but contrasts. As of such, every contrast is enhanced, producing a even color. But at the right edge of the image, we see a single pixel wide white line. This is because the brightest pixel always get the highest possible intensity level when we apply histogram equalization. For an intensity image, the highest intensity will produce white colors. As of such, we can use this image as a proof that the routine works correctly. |
![]() |
Example 2 |
This image also consist of vertical lines, but here the lines are thicker and thus there is fewer colors in the image. As histogram equalization enhances the contrasts in a image, we should see a different result than in the previous example. |
![]() |
In this image, we have broader lines resulting in fewer contrast lines. And as we know, histogram equalization is used for enhancing contrasts. When we apply equalization, the areas of the image where the colors change will be enhanced. Since the areas with changing colors are significant smaller than the areas where the colors do not change, the resulting color here will be quite dark. Histogram equalization will, as an effect, increase the highest intensity to max. This will result in white color in the areas where the color in the orginal image do not change. The image below is a classic example of local histogram equalization. |
![]() |
Example of use |
Grey Scale Images |
|
This images are of Mari-Ann Akerjord. She is one of two teachers in Bildebehandling 2004. Thanks ;-) |
|
Orginal image |
Orginal image in 8-bit greyscale |
Image filtered to the edges with a 3x3 mask |
|
Image filtered with white edges and a 21x21 mask |
Image filtered to the edges with a 21x21 mask |
Image filtered with a 101x101 mask and croped edges |
Image filtered to the edges with a 101x101 mask |
Color Images |
|
Orginal image |
Image filtered to the edges with a 3x3 mask |
Image filtered with a 101x101 mask and croped edges |
Image filtered to the edges with a 101x101 mask |
|
Image filtered with black edges and a 21x21 mask |
Image filtered with light grey edges a 21x21 mask |
Image filtered to the edges with a 21x21 mask |