"OpenCV image Processing" Ten, image histogram and related processing (the)

Source: Internet
Author: User


Histogram is an important basic tool in digital image processing, before we discuss various spatial image processing, we must first understand the concept of histogram and its meaning.



The histogram provides the statistical information of the image and provides a foreshadowing for understanding the connotation of various spatial enhancement techniques. In addition, histogram manipulation can also be used directly for image enhancement. At present, most digital cameras have the function of displaying the histogram of the photos taken, the histogram can show the gray distribution of the whole picture, can judge the proper exposure of the image according to the gray distribution shown in the histogram, and help to set up various parameters before shooting, such as sensitivity, aperture, shutter speed and exposure time.



1. Grayscale Histogram



The histogram is the statistic of the digital image. For a grayscale image, the gray-scale histogram reflects the statistics of different gray-level pixels in the image, and describes the distribution of the pixel grayscale. The grayscale histogram of a digital image is a one-dimensional discrete function defined as





Among them, RK represents the K gray level, NK indicates that the gray value is rk the frequency of pixels in the image, L represents the grayscale series.



In an image, the ratio of the frequency of the pixels in which the grayscale value is RK to the total number of pixels, called the probability histogram, can be expressed as:






, n is the total number of pixels in the image, and the equal coordinates actually represent the probability distribution of the gray-level RK. Therefore, in the probability histogram, the sum of all gray level probabilities equals 1.



Two properties of the histogram of the image:



1. The histogram represents the statistics of the different grayscale pixels in an image, which can only reflect the frequency (probability) of the different grayscale values in the image, not the location of the pixels, and other information.



2. There are many-to-one mappings between the image and the histogram, that is, different images may correspond to the same grayscale histogram.



The application of image histogram in three aspects of Digital image processing:



A. Histograms can be used to determine whether an image is reasonably using all possible grayscale levels. Intuitively, if the pixel value of an image fully occupies the entire gray scale range and the distribution is more uniform, then such an image has high contrast and multi-grayscale order. By checking the grayscale histogram, you can determine the direction of the device parameter adjustment, or gray level transformation rules, such as gamma correction.



B. There is a correspondence between the visual effect of the image and its histogram, and the change of the shape of the histogram has a corresponding effect on the image. Some properties of the image can be inferred from the histogram: the histogram of the bright image tends to the side of the gray level, and the histogram of the gray image tends to the lower gray level; the histogram of low contrast image is concentrated in the narrow range of gray scale, and the histogram of high contrast image is wide and the distribution of pixels is more uniform. Therefore, the processing of histograms can play an important role in image enhancement.



C. Histogram can be used to determine the appropriate threshold in the image segmentation, and can be based on the histogram area of the pixel statistics.



2. Cumulative histogram



The cumulative histogram is actually the cumulative probability distribution of the probability histogram p (RK) about the gray level RK, defined as:





Among them, RK represents the K gray level, NK is the frequency, n is the total, C (RK) represents the total probability that the gray value falls in the interval [0,rk] pixels in the image, L represents the gray scale series. It is important to note that the cumulative histogram must be incremental (not necessarily strictly incremented), and the cumulative probability value of the L gray level must be equal to 1.



3. Component histogram of color images



The above-mentioned histogram is for the grayscale image, the following is mainly to consider the situation of color images. Because in a color image, the color of each pixel is a vector of 3 component values. So so-called color image histogram, in fact, the r,g,b component of all the pixels in the image of the 3 components of the histogram. The 3-component black-and-white printing effect is actually 3 grayscale images, the following considerations how to convert a color image into a grayscale image method.



If one component of the R,g,b three component is extracted directly as the grayscale of the resulting image, the other two components are placed at the same size as the selected component, which is similar to the effect of black and white printing. However, this way of dealing with the corresponding shortcomings, the display effect is not very ideal, after all, two of the components are ignored, and they are also contributing to the final display effect. Therefore, the following method is generally used, there are roughly 3 kinds.



A. Average method:



The three primary colors of each pixel are equal to the average of 3 components of red, green and blue, so that the pixel values in the resulting image are evenly factored into the effect of the 3 components, and the formula can be expressed as:







B. Maximum value method:



The three primary colors of each pixel are equal to the maximum value of 3 colors of red, green and blue, with the formula:







C. Weighted Average method:



The weighted average method gives 3 different weights for red, green and blue, and then adds the formula as follows:







The sensitivity of the human eye to the three primary colors from high to low is green, red, and blue, so the value of the three primary color value relationship should be WG>WR>WB, by the YUV color space, when r=g=b=0.299r+0.587g+0.114b, can get the most appropriate grayscale image.



4. Histogram processing:



The histogram processing is also a point processing method, which realizes the image enhancement effectively by transforming the gray histogram. Histogram processing mainly has two methods: histogram equalization and histogram stipulation. Histogram equalization is the transformation of the input image into an image with uniform distribution histogram through the gray level transformation. More generally, histogram regulation refers to converting an input image into an image with a specific distribution histogram through a grayscale transformation.



A. Basic theory



The function of histogram processing is to extend the dynamic range of gray scale by the histogram obeying uniform subdivision or other specific function form. Improve the contrast of the image, enhance the local details and so on.



Set R indicates the gray level of the input image, the probability distribution rate is PR (r), s represents the gray level of the output image, its probability distribution law is PS (s), in which 0<=r,s<=1, histogram processing is the selection of gray-level transformation function, making



s = T (R)



, T (R) is a transform function, and the selection of T (R) should meet the following criteria:



(1). T (R) is a strictly monotonically increasing function within the interval 0 <= r <= 1



(2). For 0 <= R <=1, there are 0 <= T (r) <=1



The 1th condition ensures that the order of gray level from dark to bright is constant, and the inverse function is guaranteed; the second condition guarantees that the output grayscale level has the same gray scale range as the input gray level. The inverse function that satisfies the above conditions is expressed as:



R = t^ ( -1) (s)



The inverse function also satisfies the above two conditions.



B. Histogram equalization



When the pixel values in the histogram are concentrated in a narrow gray scale range or unevenly distributed, the image renders a poor contrast. Because the histogram of an appropriate contrast image has a wide gray scale range, and the distribution is relatively flat,



The purpose of histogram equalization is to transform the gray level probability distribution of histogram into uniform distribution.



For L-Grayscale digital images, the probability distribution rate after histogram equalization does not conform to uniform distribution. Set the K gray level for RK, with the gray value rk The number of pixels is NK, the total number of pixels is N, histogram equalization of the specific steps to perform the following:



(1). Calculate the probability distribution law of the gray level rk of the input image PR (RK), the probability of the pixel occurrence of each gray level RK is:






(2). Calculate the cumulative probability distribution rate of the input image Gray-level RK fr (RK):






(3). Determine the mapping relationship between the input grayscale and the output gray level Rk→sk, the RK in the input image is mapped to the corresponding pixel in the output image with the gray level of SK.



(4). Statistics the number of pixels of each gray level SK in the output image, and calculates the probability distribution rate PS (SK) of the output image gray level sk.



It should be noted that in the gray level is discrete form, gray level mapping after the gray value of SK generally does not fall on the quantization of the gray level, so the gray value of SK approximation to the nearest quantization gray-level SK. Therefore, the same gray level of pixels in the histogram cannot be split, while pixels of different grayscale levels are usually merged, resulting in a reduction in the grayscale progression used, resulting in loss of detail information.



Finally, the purpose of the histogram equalization is that the pixel value of an image occupies all possible gray levels and distributes as evenly as possible, although it can improve the contrast of the image from the visual effect, but, because the histogram of the smaller probability of gray scale into less than a few or a gray range, Thus, the grayscale resolution of the image is reduced, and some details are in the gray level with smaller probability, so the gray level is merged into other gray level, which results in the loss of the detail information of the image.



Therefore, the existing research shows that a good image enhancement (restoration) algorithm should make the histogram of the processed image consistent with the histogram of the source image in the overall shape. Therefore, the main problem of histogram equalization is that the shape of the histogram is distorted, so that the processed image appears to be lack of authenticity and naturalness.



B. Histogram-mandated



The histogram equalization described above can enhance the contrast of the image, but it does not control the specific enhancement effect, more generally, it is required that the image has a specific histogram, in order to selectively enhance the image of a particular gray scale range, or to meet the specific needs of subsequent processing.



The purpose of the histogram specification is to transform an image with a histogram that has always been a histogram of a particular shape, or to specify a histogram of the shape of the user interaction, and thus also known as "histogram matching"



It can be seen that histogram homogenization is a special case of histogram regulation, because it transforms the histogram of the input image into a histogram that obeys the uniform distribution.



For digital images, because the histogram is discretized, different gray-level pixels can be merged, the same gray level of pixels cannot be split, so different mapping relationships, will produce different prescribed results. Set the digital image with L gray level, the input image of the gray level of RK, with the gray value rk The number of pixels is NK, the histogram stipulates that the specific executable steps are as follows:



(1). Histogram equalization for the probability histogram PR (RK) of the input image, which is the cumulative histogram of the calculated PR (RK)






(2). Histogram equalization for the specified histogram PV (VJ) is calculated as a defined cumulative histogram:






(3). Map the input gray level to the new grayscale level based on the forward mapping SK→VT or the backward mapping Vt→sk proximity principle, which is to find K and L to satisfy the condition:



(4). Determines the mapping relationship between the input grayscale and the output gray level RK→VK, maps the pixels in the input image to the gray level rk to the corresponding pixels in the output image with a grayscale level of VK.



(5). Statistics the number of pixels of each gray level VK of the output image, and calculates the probability histogram of the output image.


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.