Histogram equalization (Tonal homogenization) (i)

Source: Internet
Author: User
Tags scale image

Continue to discuss the features of the Photoshop (PS) image > Adjustment (Adjust) menu. Before reading this article, you need to look at the histogram first.

Http://dbis.nankai.edu.cn/multimedia/color/f9784916187e374a20a4e984.html

tonal homogenization (equalize)

Keywords: histogram correction; histogram equalization; histogram uniformity; grayscale histogram equalization

Photoshop Menu: Image > Adjustments > Tonal homogenization

Formula:

(in the formula, SK represents a balanced grayscale value, ∑ represents the sum, NJ is the number of pixels of a grayscale level J in the original image, and the range of J is 0~k,n is the total number of pixels.) )

The equalize command re-distributes the luminance values of the pixels in the image so that they render the luminance level of all ranges more evenly. With this command, Photoshop attempts to histogram-equalize the image (histogram equalization), which distributes the grayscale values of each color scale evenly across the entire grayscale range.

You can use the equalize command when the scanned image appears darker than the original, and you want to balance the values to produce a lighter image. With the tonal homogenization command and the histogram command, you can see the before and after comparisons of brightness.

Use the Tonal homogenization command:

1. Select menu Image > Adjust > Tonal homogenization.

2. If you have selected an image area, select the content to be homogeneous in the pop-up dialog box, then click OK.

only tonal homogenization selected area distributes only the pixels of the selection evenly.          Equalize entire image based on selected region the pixels of all images are evenly distributed based on the pixels in the selection. principle

histogram equalization is a gray-scale transformation algorithm, so we focus on the histogram equalization of gray-scale image. absolutely uniform .

Figure A is a black-and-white gray uniform gradient, the number of shades of each 0~255 is the same. Figure B is that the pixels of figure A are scrambled in the order of random distributions, and the number of each grayscale is the same as in figure A, so its histogram is also the same as figure A.

Histogram of figure A and Figure B. Each grayscale quantity is the same, and the histogram appears as a black rectangle.

approximate uniformity

For the general image, because the number of pixels in each grayscale is not the same, we have no way to adjust the components of each gray scale as shown in Figure A, b so evenly, but can be nearly uniform. That is, the histogram is divided evenly into several, so that each part of the number of pixels roughly equal.

Here is a histogram of a picture, a total of 19,200 pixels, from left to right evenly divided into three parts. After equalization, the number of pixels per share is around 6400.

manual Adjustment method

The photos we take or scan tend to be too light or too weak to make the contrast of the image weaker and the details not clear. This kind of image histogram is often concentrated in a range of tonal scale, we need to stretch these gray levels to the entire gray level, and make them evenly distributed in the histogram, in order to achieve the purpose of enhancing the image.

Now we're going to adjust the grayscale distribution of a picture by Photoshop's curve adjustment (Image > Adjustment > Curve).

The histogram graph above can be approximated as three peaks and two troughs. First, the beginning and end of the curve (black-and-white field) pull to the width of the graph, and then through the curve to the two trough to pull higher, then the gray scale distribution appears to be more uniform.

The image and histogram after adjustment.

histogram equalization is to use an algorithm to achieve the effect of the above manual adjustment. algorithm classic algorithm

The following is an example of a simple picture of 3*2 pixels (Figure C) to illustrate the equalization algorithm for grayscale histogram.

(Figure C)

Histogram of Figure C:

Take a look at the percentile (percentile). The percentile for the general software is the number of pixels in the current color scale ÷ the total number of pixels, while Photoshop shows the number of pixels in the current level and the front-level of the Pixel ÷ the total number of pixels. So the figure C level of 100 is the percentile is (3+2)/6=5/6=83.33%, this percentile is actually we require the gray value (range 0~1), convert it to 0~255 range, to multiply by 255.

After finding the percentile of each color scale, multiply by 255, we can find its corresponding gray value.

percentile percentile
Color Scale Quantity Frequency of Occurrence Sub-255* hundred
50 3 3/6 3/6=50% 255*50%=128
100 2 2/6 (3+2)/6=83.33% 255*83.33%=212
200 1 1/6 (3+2+1)/6=100% 255*100%=255

A grayscale mapping table is formed based on the corresponding relationship of the levels of each color scale->255* percentile, and then the gray values of each pixel of the original picture are modified according to the mapping table. For figure C, replace 50 with 128, replace 100 with 212, replace 255 with 200. In this way, the grayscale histogram equalization is completed.

Photoshop's algorithm

After the classic algorithm equalization picture, the brightest pixel value is always 255, because the last level of the color scale (255) of the percentile must be 100%. The darkest is determined by the number of levels 0, and the pixel value is not necessarily 0.

Photoshop uses the method of contrast stretching to make the darkest pixel value 0, the other pixels darker, and the brightest pixels to remain 255 unchanged. The effect of contrast stretching may be slightly darker than the classic algorithm.

The contrast stretch algorithm, similar to the effect of setting the Black field to min using the Color scale adjustment command, is the first color scale with a number of pixels not 0.

Formula for contrast stretching: C = (level-min) * scale = (level-min) * 255/(255-min)

Figure C After the equalization of gray values are 128, 212, 255, for the sake of precision, we use the form of 2 decimal places (127.50, 212.42, 255.00) for the calculation of contrast stretch.

min = 127.50 ' min After equalization scale
= 255/(255-min) = 2

(127.50-min) *scale = 0*2 = 0
(212.42-min) *scale = 84.92*2 =
255.00-min *scale = 127.5*2 = 255

' New mapping Table:
0,
255

A histogram comparison between the classical algorithm and the Photoshop algorithm.

color algorithm

Color histogram equalization is actually the image of one or more color channels for grayscale histogram equalization operation, there are several common methods:

Statistics the histogram of all RGB color channels and do the equalization operation, and then replace the R, G, b channel color values according to the Balanced mapping table respectively.

Statistic the histogram data of R, G, B color channel separately and do the equalization operation, then replace the R, G, b channel color values according to the map table of R, G and B respectively.

The luminance channel is calculated using the luminance formula or the average of the RGB, then the data of the histogram of the luminance channel is counted and balanced, then the R, G, b channel color values are replaced according to the mapping table respectively.

Photoshop is using the first method. Summary

Histogram equalization is an important application of gray-scale transformation, it is efficient and easy to implement, it is widely used in image enhancement processing. The pixel gray change of the image is random, the graph of the histogram is high and low, the histogram equalization is using certain algorithm to make the histogram broadly peaceful.

The image after equalization treatment can only be approximately evenly distributed. The dynamic range of the balanced image expands, but its essence is to enlarge the quantization interval, and the quantization level decreases, therefore, the original gray-scale different pixels may become the same after processing, forming a region of the same gray scale, there are obvious boundaries between the regions, thus appearing pseudo-contour.

If the original image contrast is very high, if the balance of the grayscale harmonic, the contrast decreased. In a white-toned image, equalization merges some pixel grayscale to increase contrast. If the picture is balanced again, the image will not change.

Gray histogram equalization algorithm, simply speaking, is the histogram of each gray level of the normalization process, the cumulative distribution of each gray scale, get a map of the gray Scale mapping table, and then according to the corresponding gray value to correct each pixel in the original image.

The classic histogram equalization algorithm may have some of the following disadvantages: The actual gray range of the output image is difficult to reach the maximum allowable gray range of the image format.           Although the gray-scale distribution histogram of the output image is nearly uniform, it is possible that the value and the ideal value of 1/n still differ greatly, not the optimal value. The grayscale level of the output image may be too large to be merged. The loss of image information is easily caused by the engulfing of gray scale.

For this reason, many improved histogram equalization algorithms are proposed, please refer to the resources provided at the end of this article for more information.

formula

the students who want to write a paper may need to describe it in a mathematical way, and I will summarize the contents of the above as a formula for reference. probability density function (PDF)

In order to calculate convenience, we need to normalized the histogram, that is, the gray range from 0~255 to 0~1. Normalized histogram is actually a probability density function (pdf,probability density function), equalization is to make the probability density of 1.

We use PR (r) to represent the original image of the PDF, using PS (s) to indicate that after the equalization of Pdf,r, S, respectively, represents the grayscale value before and after the equalization, r,s∈[0,1]. Based on the knowledge of probability theory, it can be concluded that:

The T-1 (s) in the formula represents the inverse transformation function of T (R).

Because we require a probability density of 1, namely:

So:

This concludes: ds = Pr (r) * Dr

With the R integral on both sides of the equation, you can derive the PDF's equalization formula:

T (r) in the formula represents the gray-scale transform function of R, ∫ is the integral, and w is the hypothetical variable. cumulative distribution function (CDF)

For images, we need to use a discrete form of formula (discrete formulation).

The probability of a gray level pixel appearing is: Pr (RK) = nk/n

Pr (RK) is the probability that the original image K gray level pixels appear, RK is the K gray level, that is, the current color scale k,k∈[0,1]. NK is the number of RK pixels. N is the total number of image pixels (image size), N=∑knk.

Grayscale histogram equalization formula for images:

In the formula, T (RK) is a conversion function that represents the K-gray level of the original image. The ∑ represents the sum. The ∑nj/n represents the ratio of the sum of pixels in the 0~j grayscale to the total number of pixels, that is, the percentile (the number of pixels in the current level and the front of the foreground) ÷ the total number of pixels. ∑PR (RK) indicates the cumulative summation of the probability of the gray level of the 0~k. Because S is the normalized value (s∈[0,1]), to be converted to 0~255 's color value, it needs to multiply by 255, i.e. S=∑PR (RK) *255.

This conversion formula is also known as the cumulative distribution function for images (cdf,cumulative distribution functions).

Related information

Use the Tonal homogenization command (Photoshop) http://www.8esky.com/handbook/photoshop7/Help/1_8_17_3.html

Visual C + + implements Digital Image enhancement processing http://www.yesky.com/20021224/1645640_1.shtml

The color correction http://www.pcbookcn.com/article/2358.htm of images in VB image processing

Histogram equalization Image enhancement algorithm based on local contrast enhancement http://www.ahcit.com/lanmuyd.asp?id=1536

An algorithm for night-time image enhancement http://www.wanfangdata.com.cn/qikan/periodical.Articles/qhdxxb/qhdx99/qhdx9909/990922.htm

Image processing Technology http://www.fjtu.com.cn/fjnu/courseware/0334/course/_source/web/lesson/char6/j2.htm

Application of vc++6.0 in grayscale Digital Image enhancement processing http://dev.yesky.com/43/2591543.shtml

Histogram equalization http://fourier.eng.hmc.edu/e161/lectures/contrast_transform/node3.html

Histogram equalization http://www.clarkson.edu/class/image_process/qa1/Histogram%20Equalization.htm

Image processing fundamentals-histogram-based Operations http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/ Fip-istogram.html

Point Operations-histogram equalization http://homepages.inf.ed.ac.uk/rbf/HIPR2/histeq.htm

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.