Current location - Training Enrollment Network - Mathematics courses - Square equilibrium
Square equilibrium
The function of histogram equalization is image enhancement. The process is to map the pixel distribution of an image to another distribution by one method, and the cumulative distribution function is mainly used in the mapping process. Cumulative distribution function is used to describe the probability distribution of random variables (f (x) = p (x

Let's look at an example first.

Suppose there is the following image:

As shown in the following figure, obtain the statistical information of the image and complete the gray value mapping according to the statistical information:

The mapped image is as follows:

As can be seen from the above example, when one pixel value is converted into another pixel value, the original size relationship has not changed, but if the square graph is drawn directly, the histogram will slow down.

1. Declare original image, target image and form name: Declare source image and target image and window name:

2. Load source image: Load source image:

3. Convert it to grayscale:

4. Use the function equalizeHist to equalize the histogram of the gray image above: Use the function cv:: equalizehist to apply histogram equalization:

As you can see, the parameters of this operation are only the source image and the target (after equalization) image. It is easy to see that the only parameters are the original image and the output (equalized) image.

5. Display these two images (source image and balanced image): Display two images (original image and balanced image):

6. Wait for the user until the user exits the program.

1. In order to better observe the effect of histogram equalization, we use a picture with weak contrast as the source image input, as shown below: In order to better approximate the equalization result, let's first introduce a picture with little contrast, such as:

Its histogram is: By the way, it has this histogram:

Note that most pixels are concentrated on the intensity in the middle of the histogram. Note that pixels are clustered around the center of the histogram.

2. After using the routine for equalization, we get the following results: After using our program to apply equalization, we get the following results:

This picture is obviously more contrasting. Check the histogram of the balanced image again. There must be more contrast in this picture. View its new histogram, as shown below:

Notice that the pixels are now evenly distributed throughout the intensity range. Pay attention to the distribution of the number of pixels in the whole intensity range.

Zhilily @ opencv Chinese website < zhlifly@gmail.com >

Mathematical principle of histogram equalization