[Reproduced + original] emgu CV on C # (3) -- emgu CV on Equalization

Source: Internet
Author: User

This article briefly describes the equalization principle and mathematical implementation, and finally uses emgucv to achieve gray-scale balancing of images.

Histogram equalization is a common method for image enhancement.

I. equalization principle and mathematical implementation (reproduced)

For more information about the principles and mathematical Implementation of equalization, see histogram equalization and image processing (3) _ grayscale distribution equalization.

Grayscale distribution equalization is also called histogram equalization.

1. Overview

This method is usually used to increase the global contrast of many images, especially when the contrast of useful data is very close. In this way, the brightness can be better distributed on the histogram. This function can be used to enhance the local contrast without affecting the overall contrast. histogram equalization is implemented by effectively expanding the commonly used brightness.

This method is very useful for images with too bright or too dark backgrounds and prospects, this method, in particular, can bring better bone structure display in X-ray images and better details in photos of over-exposure or under-exposure. One of the main advantages of this method is that it is a fairly intuitive technique and reversible operation. If the equalization function is known, the original Histogram can be restored, and the amount of computing is not large. One disadvantage of this method is that it does not select the processed data. It may increase the contrast of background noise and reduce the contrast of useful signals.

2. Principles and mathematical implementation

Let's look at a grayscale image and let Ni represent the number of occurrences of grayscale I. In this way, the probability of occurrence of pixels whose grayscale is I in the image is

L indicates the gray scale in the image, N indicates the gray scale in the image, and P is actually the histogram of the image, which is normalized to 0... 1.

Use C as the cumulative probability function corresponding to P, and define it:

C is the cumulative normalized histogram of the image.

We create a change in the form of Y = T (XI), which generates a Y for each value in the original image, in this way, the cumulative probability function of Y can be linear within all values. The conversion formula is defined:

Note that t maps different levels to the 0... 1 domain. to map these values back to their original domain, you need to apply the following simple transformation in the result:

The histogram equalization method is used for Grayscale Images. However, this method can be used for the red, green, and blue components of RGB color values.

The above is Wikipedia's explanation of the principle of histogram equalization. The conversion to algorithm description is as follows:
(1) obtain the histogram of the target image.

(2) obtain the gray density distribution from the histogram graph. The number of pixels in each gray level/The total number of pixels in the gray level histogram]

(3) accumulate the density histogram. Each gray-level density is the sum of the previous gray-level density.

(4) traverse the original image. Each pixel value is the accumulated probability density index value and is multiplied by 255 to restore the image.

Ii. Program Implementation

For the programming method of opencv, see [opencv Getting Started Guide] Chapter 9 grayscale histogram equalization.

The emgucv programming method is quite simple. The function used is cvequalizehist.

The main framework of the program can use the program files in the [reprint + original] emgu CV on C # (2)-emgu CV on grayscale article.

Add the third picturebox to the form and set sizemodel to zoom

Add the following program function directly after the grayscale function, so easy.

 

// Balance intptr histimg = cvinvoke. cvcreateimage (cvinvoke. cvgetsize (srcimg), emgu. CV. cvenum. ipl_depth.ipl_depth_8u, 1); cvinvoke. cvequalizehist (grayimg, histimg); miplimage histmi = (miplimage) Marshal. ptrtostructure (histimg, typeof (miplimage); image <gray, byte> histimage = new image <gray, byte> (histmi. width, histmi. height, histmi. widthstep, histmi. imagedata); picturebox3.image = histimage. tobitmap ();

 

 

Iii. Result Analysis

Cut down the image processed in chapter 9 grayscale histogram equalization in [opencv Getting Started Guide]. Since only grayscale images are used, grayscale processing is also performed on the image, then, the processed images are balanced.

1. original program Image

2. Obtain the grayscale image by cutting

3. Use the emgucv Method for equalization. The final image obtained is compared with the image obtained in the original article.

Original article Image

After balancing this article

 

Reprinted please indicate the source, original address: http://www.cnblogs.com/MobileBo/p/3917956.html

All are called the same DLL, so the difference is not very big, but the emgucv method is phased again, causing some details loss.

According to the finishing effect, the expected requirements have been met. The grayscale histogram equalization significantly enhances the grayscale image and the contrast.

 

Related Article

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.