Image vertex operations-underlying code and Halcon library functions, halcon library functions

Source: Internet
Author: User

Image vertex operations-underlying code and Halcon library functions, halcon library functions

The most basic image analysis tool-grayscale histogram. With histogram assistance, four gray-scale transformations can be implemented, including linear gray-scale transformation (grayscale stretching), gray-scale logarithm transformation, gray-scale gamma transformation, and gray-scale piecewise linear transformation. histogram correction technology is used, two major transformations can be implemented, including histogram equalization and histogram normalization.

1. grayscale Histogram

The grayscale histogram consists of a general grayscale histogram and a normalized grayscale histogram. The grayscale histogram counts the number of occurrences of each gray level in the image, while the normalized grayscale histogram counts the frequency of occurrence of each gray level. Therefore, the grayscale histogram is usually quantitative,Total number of pixels and number of gray pixelsIn qualitative aspects, we can see thatOverall gray dynamic rangeThat is, the contrast and brightness.

In the bottom-Layer Code that uses C # to draw a general grayscale histogram, the core of the algorithm flow is to calculate the number of pixels at each grayscale level, while the normalized grayscale histogram is drawn, the core of an algorithm flow is to calculate the gray level, that is, the cumulative distribution function. The Code is as follows. However, the code can be viewed at will in the Halcon library.

Byte * Init_byte = (byte *) BMP data. scan0; // you must first traverse rows and then traverse columns for (int I = 0; I <BMP data. height; I ++) {for (int j = 0; j <BMP data. width; j ++) {// calculate the number of pixels of different gray levels temp = * Init_byte; CountPix [temp] ++; // change the column Init_byte ++ ;} // line feed Init_byte + = BMP data. stride-BMP data. width ;}for (int k = 0; k <256; k ++) {// calculate the cumulative number of pixels at different gray levels if (k! = 0) {CumulatePix [k] = CumulatePix [k-1] + CountPix [k];} else {CumulatePix [0] = CountPix [0];}

 

Ii. linear and nonlinear transformation of gray scale

The purpose of grayscale conversion is to enhance the gray contrast of the image and achieve the goal of ideal preprocessing. Linear gray-scale transformation. The core of C # encoding is to traverse all the pixels of the image and add a multiplication coefficient and a addition coefficient to each pixel, adjust two parameters to achieve the expected results (Note: processing the cross-border value (0-255); Non-linear gray transformation, including logarithm transformation and exponential transformation, Gamma transformation and piecewise transformation, code implementation is the same, but the difference is thatThe grayscale extension and compression function of the image. It expands the low grayscale value and compresses the high grayscale value.Or, on the contrary, make the gray-scale distribution of the image more consistent with the human visual features or the gray-scale contrast is stronger. In Halcon, the corresponding operators are scale_image, scale_image_max, log_image, exp_image, and pow_image. segment conversion is troublesome. Generally, overpaint_region is used to transform the region in the image. Therefore, segment transformation is suitable for implementation at the underlying layer.

Unsafe {byte * Init_byte = (byte *) mbpdata. scan0; for (int I = 0; I <mbpdata. width; I ++) {for (int j = 0; j <mbpdata. height; j ++) {value = k * (* Init_byte) + B; // process the cross-border value if (value> 255) {* Init_byte = 255 ;} else if (value <0) {* Init_byte = 0;} else {* Init_byte = (byte) value;} Init_byte ++;} Init_byte + = mbpdata. stride-mbpdata. width ;}}

 

3. histogram balancing and histogram Normalization

Histogram balancing is a histogram Correction Method Based on the transformation of the cumulative distribution function to generate images with a gray-level probability even distribution. It is mainly used to enhance images with a smaller dynamic range to improve the gray contrast. The core algorithm flow using C # encoding: 1. normalize the gray scale value; 2. Set the even probability distribution for the gray scale of the image, that is, p = 1. Image normalization is to convert the image into a unique standard form to resist various transformations and perform gray-scale even distribution on this basis.

Therefore,When the histograms of the original image are different and the structural content of the image is the same, the visual consistency of the histogram equalization is almost identical.Later, scholars successively proposed Adaptive histogram equalization algorithms (AHE) and adaptive histogram equalization (CLAHE) with limited contrast ). The essence of the defog algorithm is to adjust the image contrast and brightness. Therefore, CLAHE is widely used in defog algorithms.

In Halcon, histogram equalization is just a piece of code, equ_histo_image.

Byte * Init_byte = (byte *) BMP data. scan0; // you must first traverse rows and then traverse columns for (int I = 0; I <BMP data. height; I ++) {for (int j = 0; j <BMP data. width; j ++) {// calculate the number of pixels in different gray levels. temp = * Init_byte; CountPix [temp] ++; Init_byte ++;} Init_byte + = BMP data. stride-BMP data. width ;}for (int k = 0; k <256; k ++) {// calculate the cumulative number of pixels at different gray levels if (k! = 0) {CumulatePix [k] = CumulatePix [k-1] + CountPix [k];} else {CumulatePix [0] = CountPix [0];} // perform one-to-one ing based on the gray value. Pay attention to the Operation Sequence and parentheses to prevent only integer 0. pixMap [k] = (byte) (255 * CumulatePix [k]/bytes + 0.5);} byte * Init_byte2 = (byte *) BMP data. scan0; for (int I = 0; I <BMP data. height; I ++) {for (int j = 0; j <BMP data. width; j ++) {// histogram equalization to obtain the grayscale level. The temp ing temp = * Init_byte2; * Init_byte2 = PixMap [temp]; Init_byte2 ++;} Init_byte + = BMP data. stride-BMP data. width ;}

Histogram equalization is not only easy to operate and effectively enrich the gray level, but this process is not controlled. Therefore, histogram normalization or Histogram Matching is introduced. Histogram normalization is essentially a fitting process. Therefore, the contrast and brightness of a normalized image are similar to that of a standard image. The histogram-based algorithm flow is based on the histogram equalization. The position of the minimum difference of the cumulative distribution probability is counted and mapped one-to-one.

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.