OPENCV3 Programming Primer Note (4) corrosion, expansion, opening and closing operations, diffuse water filling, pyramid, thresholding, Hough transform

Source: Internet
Author: User
Tags scalar

19 corrosion Erode, expansion dilate

Corrosion and swelling are for the white part of the image (highlighted part), not black. In addition to the input and output images, there are three options to be passed into the template operator Element,opencv: rectangular morph_rect, cross-shaped morph_cross, oval morph_ellipse. There will be a little more templates in Matlab.

For example:

Mat element = Getstructuringelement (Morph_rect,size (15,15));

Erode (srcimage,dstimage,element);

Imshow ("corrosion Diagram", dstimage);

Dilate (srcimage,dstimage,element);

Imshow ("Expansion map", dstimage);

20 opening and closing operations, morphological gradients, top caps, Black Caps

Open operation is the process of first corrosion and expansion, the open operation can be used to eliminate small objects, the slender point of separation of objects, and smooth the boundaries of larger objects while not significantly changing their area.

The closed operation is the process of first swelling and corrosion, which can eliminate the small black hole (dark area), which is the formation of the connected domain.

The morphological gradient is the difference of the corrosion diagram of expansive map, which can be used to preserve the edge contour of the object.

The top hat is the difference between the original image and the result graph of the open operation, and the top hat operation is often used to separate patches that are lighter than the neighboring point. In cases where a picture has a large background and a small item is more regular, the top hat operation can be used for background extraction.

Black Hat is the difference between the closed operation result graph and the original image, and the Black Hat operation is used to separate patches darker than the neighboring points.

21 Diffuse water filling

The diffuse fill method is a type of connected area filled with a specific color, often used to mark or separate part of an image for processing or analysis. Its implementation function is FloodFill.

Rect Ccomp;

FloodFill (Srcimage,point (50,300), scalar (155,255,55), &ccomp,scalar (20,20,20), scalar (20,20,20));

Imshow ("Diffuse water filling diagram", srcimage);

The point (50,300) is of type dot, which represents the beginning of the diffuse fill, and the Scalar (155,255,55) represents the value of the pixel being dyed, that is, the new value of the de-oiling pixel is redrawn, and &ccomp is the rect* type with a default value of 0. Used to set the minimum bounding rectangle area where the FloodFill function will redraw the region; The fifth parameter, scalar (20,20,20), represents the maximum value of the luminance or color difference between the current observed pixel value and its part neighborhood pixel value, or the seed pixel to which the part is to be added; the Sixth parameter scalar (20,20,20) represents the maximum value of the positive difference between the current observed pixel value and its part neighborhood pixel values or the seed pixels to be added to the part;

22 image Pyramid and image size scaling

We often convert images of some size to other sizes, and if you want to enlarge or reduce the size of the image, there are two ways in OpenCV:

(1) The Resize function is the most direct

Resize (srcimage,dstimage,size (), 0.5,0.5);//shrink to half

Imshow ("Zoom 1/2 graph", dstimage);

Resize (srcimage,dstimage,size (), 2,2);//magnification twice times

Imshow ("Enlarge twice times graph", dstimage);

Resize (srcimage,dstimage,size (srcimage.cols*3,srcimage.rows*3));//magnification 3 times times

Imshow ("Enlarge 3 times times Graph", dstimage);

All examples above are interpolated in the default linear interpolation liter_linear, and can also choose nearest neighbor interpolation Inter_nearest, region interpolation Inter_area, three spline interpolation inter_cubic,lanczos interpolation Inter_ LANCZOS4.

(2) Pyrup (), Pyrdown () function, which is the image-pyramid-up sampling and down-sampling operation function.

There are generally two types of pyramids: 1. Gaussian pyramid, downward sampling is the size reduction, the implementation function is pyrup;2. Laplace pyramid, the upward sampling, that is, the image size amplification, the implementation function is Pyrdown.

Similar to the Resize function implementation, Pyrup (Srcimage,dstimage,size (srcimage.cols*2,srcimage.rows*2));//magnification twice times

Imshow ("pyramid magnification twice times graph", dstimage);

Pyrdown (Srcimage,dstimage,size (SRCIMAGE.COLS/2,SRCIMAGE.ROWS/2));//reduced by twice times

Imshow ("Pyramid Reduction twice times graph", dstimage);

23 Threshold value

The threshold is the simplest image segmentation method, which is based on the gray difference between the object and the background in the image, and this segmentation belongs to the pixel-level segmentation. Threshold operations are divided into fixed threshold operation threshold and adaptive threshold Operation Adaptivethreshold. The Ps:threshold function input image can be either 8-bit or 32-bit, which can be either a grayscale or a color graph, but the adaptivethreshold input image must be 8 bits, which must be a grayscale image.

Mat Imggray;

Cvtcolor (Srcimage,dstimage,cv_bgr2gray);

Imshow ("grayscale graph. jpg", dstimage);

Imggray = Dstimage;

Threshold operation

Threshold (srcimage,dstimage,100,255,3);//Represents the threshold value, 255 represents the maximum value of the threshold type, and 3 indicates its threshold mode

Imshow ("Fixed thresholding image", dstimage);

Adaptivethreshold (imggray,dstimage,255,adaptive_thresh_mean_c,thresh_binary,3,1);//3 represents the domain size of a pixel that calculates the threshold size, with a value of 3, 5,7 and so on. 1 represents a constant value after subtracting an average or weighted average, usually a positive number, or, in rare cases, 0 or negative.

Imshow ("Adaptive thresholding Image", dstimage);

24 Hoffman Transform Hough

Hough Transform is a feature extraction technique in image processing, and the transformation of Hough transform using two coordinate space will form a peak in one space with the same shape curve or line mapping to one point of another coordinate space, thus transforming the problem of detecting arbitrary shape into statistical peak problem.

The Hough Line transformation principle uses the straight line in the polar coordinate representation case, is represented by the polar diameter and the polar angle (R,theta).

OPENCV3 Programming Primer Note (4) corrosion, expansion, opening and closing operations, diffuse water filling, pyramid, thresholding, Hough transform

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.