Image enhancement algorithm based on histogram (HE, CLAHE, Retinex) (I.)

Source: Internet
Author: User

Histogram is an abstract representation of the statistical characteristics of image color. There are many interesting algorithms that can be implemented based on histograms. For example, the image enhancement uses the histogram to adjust the image contrast, the person uses the histogram to carry on the large-scale lossless data hiding, some people also use the gradient histogram hog to construct the image characteristic and realizes the target detection. In this section, we discuss the important histogram equalization algorithm, saying that it is important because it is based on the subsequent derivation of a number of practical and interesting algorithms.


Histogram equalization


If the pixel gray value of an image is clustered in an overly limited range, then the program effect of the image is very bad, and the direct perception is that the contrast is very weak. From Wikipedia, the histogram distribution of the first picture is very uneven. If you extend the histogram evenly across the entire distribution domain, the image looks a lot better.


MATLAB provides a ready-made function "Histeq ()" To achieve histogram equalization of the image. But in order to illustrate the principle of the algorithm, the following I will be in MATLAB self-coding to achieve the image histogram equalization. The code to demonstrate this algorithm is obviously more intuitive and easier to understand. Of course, in fact, I have to sigh, if only as an image algorithm research, MATLAB is really very useful.


First read the image and convert it into a grayscale map. Then extract the length and width of the image.

Image = Imread (' unequalized_hawkes_bay_nz.jpg '); Img = Rgb2gray (image); [Height,width]=size (image);

then draw a histogram of the original image.

[Counts1, X] = Imhist (img,256); counts2 = Counts1/height/width;stem (x, counts2);


Counts the cumulative number of pixel values for each grayscale.

Numpixel = zeros (1,256);% statistics of each gray number, a total of 256 gray level for i = 1:heightfor j = 1:width% corresponding gray value pixel number increased by one because the numpixel subscript is starting from 1, However, the value range of the image pixel is 0~255, so the Numpixel (IMG (i,j) + 1) numpixel (IMG (i,j) + 1) = Numpixel (img (i,j) + 1) + 1;endend

then the frequency value is counted as the frequency

Probpixel = zeros (1,256); For i = 1:256probpixel (i) = Numpixel (i)/(Height * Width * 1.0); end

The CDF is then computed using the function cumsum, and the frequency (value range is 0.0~1.0) is mapped to the unsigned integer 0~255.

Cumupixel = Cumsum (Probpixel); Cumupixel = uint8 (255. * Cumupixel + 0.5);


Histogram equalization. At the right end of the assignment statement, IMG (I,J) is used as the index of the Cumupixel. For example, img (i,j) = 120, remove the 120th value from the cumupixel as the new pixel value of the img (i,j) .

For i = 1:heightfor j = 1:widthimg (i,j) = Cumupixel (IMG (i,j)); endend

Finally, the histogram of the new image is displayed.

Imshow (IMG); [Counts1, X] = Imhist (img,256); counts2 = Counts1/height/width;stem (x, counts2);




Of course, the above discussion is the histogram equalization of grayscale images. For color images, you might think of the R, G, and b three components separately, which is really a method. Sometimes, however, this is likely to result in distorted image color. Therefore, it is suggested that after converting the RGB space to HSV, the V component is treated with histogram equalization to preserve the color of the image without distortion. Let's do some comparative experiments. The image to be processed is the standard image processing test diagram couple diagram, as shown below.

First, we deal with R, G, b three components separately, for the sake of simplicity we directly use the function Histeq () in MATLAB.

A = Imread (' Couple.tiff '); R = A (:,:, 1); G = A (:,:, 2); B = A (:,:, 3); R = Histeq (r, 256); g = Histeq (g, 256); b = Histeq (b, N); A (:,:, 1) = R;a (:,:, 2) = G;a (:,:, 3) = B;imshow (a)

The following code uses another way to process the V channel after the color space is converted to HSV. Since the code is basically consistent with what was described earlier, we don't have much to explain here.

img = imread (' Couple.tiff '); hsvimg = RGB2HSV (IMG); V=hsvimg (:,:, 3); [Height,width]=size (V); V = Uint8 (v*255); Numpixel = zeros (1,256); For i = 1:heightfor j = 1:widthnumpixel (V (i,j) + 1) = Numpixel (V (i,j) + 1) + 1;endendprobpixel = Zeros (1,256); For i = 1:256probpixel (i) = Numpixel (i)/(Height * Width * 1.0); endcumupixel = Cumsum (Probpixel); Cumupixel = uint8 (255. * Cumupixel + 0.5); For i = 1:heightfor j = 1:WIDTHV (i,j) = Cumupixel (V (i,j)); EndEnd v = im2double ( V); Hsvimg (:,:, 3) = V;outputimg = Hsv2rgb (hsvimg); Imshow (outputimg);


Finally, the effect of different methods on color image processing is compared. The left figure below is the result of processing the three components of R, G and B respectively. The image on the right is the result of the V-channel processing in the HSV space. Obviously, the effect of the right image is more ideal, while the left image has some color distortion. In fact, histogram equalization for color images is a seemingly simple subject in the field of image processing, but it has been studied for some time. What we call the method of processing the V component in the HSV space is also a relatively basic strategy. Many related research articles have proposed a further and more adaptable color image histogram equalization algorithm. Interested readers can refer to the relevant literature for more information.


Processes the results of the R, G, and b three components respectively into the HSV space and processes the V component


This is the first article in this series, in the next article we will discuss the Clahe algorithm, which is the adaptive Histogram equalization algorithm which restricts the contrast degree.

If you're a fellow of image processing, Welcome to the image Processing Learning Group (529549320).

more interesting and useful image processing algorithms can also refer to my the principle and practice of Digital Image Processing (MATLAB edition)



Image enhancement algorithm based on histogram (HE, CLAHE, Retinex) (I.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.