OpenCV - image processing

Image Process

Filtering

Introduce the filter function in OpenCV.

The edge problem is generally considered when filtering, and all the methods of complementing the edge are introduced here . The right side of the page represents an example of the completion value. Edge completion copyMakeBoarderfunction: .

Two filtering methods:

  1. Call the corresponding Filtering function.
  2. Generating a corresponding convolution kernel, then calls Filter2Dthe function.

bilateralFilter

Bilateral filtering: The filtering method of edge preservation, which preserves the edges whose pixel value difference is greater than a certain threshold without blurring. The edge information of the image is preserved. The convolution kernel is regarded as the superposition of the spatial kernel and the color domain kernel. The airspace core represents the spatial distance, which decreases as the distance from the center point increases. The color gamut kernel represents the difference of channel values, which decreases as the phase difference increases (preserving edges, that is, where the image changes drastically, the difference is large, and the median value of the corresponding convolution kernel is small, and the impact is small). The product of the two is the core of the filtering.

blur, boxFilter, GaussianBlur, medianBlur, sqrBoxFilterIt omitted.

sqrBoxFilter The value in the area is squared and then summed, which can be used to calculate the statistical parameters of the picture.

Filter2D

The convolution formula is shown below. Shows the relationship between anchorthe kernelcenter point and the corresponding pixel point.

Insert picture description here

Ancillary use is a public getKernelfunction and the like.

pyrMeanShiftFiltering

pyrMeanShiftFiltering The picture is processed at a relatively low level. Here is how to traverse and process pixel data in detail.

  1. Iteration termination condition is determined : for TermCriteriaprocessing
  2. Construction of Gaussian pyramid : cv::pyrDown. First with a createstatement of the size of each layer picture function, then lower and lower sampling generated pyramid.
  3. Each level of pyramid traversal : traversal along the column is dptr += dstep - size.width*3( dstepthe number of bytes in a row); traversal along the row is dptr += 3, (three channels are three bytes, and 0~2 offsets are added to access different channels).

Easy access to the pointer with offset adjacent elements, so when traversing the multi .ptr()method.

  1. Adjacent airspace access : Loop unrolling optimization is used here.
  2. The lower level pyramid and the upper level map : According to the downsampling ratio, the corresponding position is calculated, and then the pointer is used to process the access.

Image pyramid

PyrUp & PyrDown

PyrDown: Downsampling the image, the original image is Gaussian convolution, and then even rows and columns are eliminated. (The so-called Gaussian pyramid process)

PyrUp : Up-sampling the image; insert 0 into the original image in even rows and columns, and then perform Gaussian convolution.

For the Laplacepyramid, a difference of each layer retained (when it returns), that the layer (image 0) to PyrDownthen PyrUpobtain an image 1, image 0 image 1 is subtracted this layer.

buildPyramid

buildPyramid : Build a Gaussian Pyramid in one step.

Morphological operation

Corrosion: Use a structural element to slide the window, and use the minimum value of the image covered by the window as the pixel value at the center of the structural element;

Dilation: Use a structural element to slide the window, and use the maximum value of the image covered by the window as the pixel value at the center of the structural element;

Operations on small areas.

Open operation: Corrosion first and then expansion, you can remove small objects in the foreground (disappear in corrosion, and cannot be restored in expansion).

Closing operation: expand first and then corrode, you can fill the small hole in the foreground (the hole is filled in the expansion, and the corrosion will not make it reappear).

Morphological gradient: It is used to describe the target boundary or edge in an area where the gray level of the image changes drastically. The morphological gradient is combined with the original image based on expansion or erosion to enhance the intensity of the pixels in the field of structural elements and highlight the highlights of the area Peripheral.

There are four types of gradients:

  1. 基本梯度: The basic gradient is the difference image obtained by subtracting the eroded image from the dilated image. The gradient image is also a method of calculating morphological gradient supported in OpenCV, and the gradient obtained by this method is called the basic gradient.

  2. 内部梯度: The difference image is obtained by subtracting the image after corrosion from the original image, which is called the internal gradient of the image.

  3. 外部梯度: It is the difference image obtained by subtracting the original image after the image is expanded, which is called the external gradient of the image.

  4. 方向梯度: Directional gradient is to use the straight lines in the X direction and the Y direction as the structural elements to obtain the image gradient, and use the X direction straight lines as the structural elements to expand and etch to obtain the image after the difference is called the X direction gradient, and use the Y direction straight lines as the structure After the elements are expanded and corroded respectively, the image is obtained and the difference is called the Y-direction gradient.

erode & dilate

Note that kernalthis parameter. Normally can getStructureElementget the function, if passed cv::Mat(), it is a square window 3 * 3. In fact, the core is just one mask. In a window, the corresponding position of the pixel included in the morphological operation is 1.

morphologyEx

The main function of morphological operations. opThe parameters determine the actual operation (opening, closing, expansion, corrosion, etc.).

Guess you like

Origin blog.csdn.net/lib0000/article/details/112846753