First, Introduction
The effect of image sharpening is to enhance the grayscale contrast, so that the blurred image becomes clearer. The essence of image Blur is that the image is averaged or integral, so the image can be inverse, such as the differential operation can highlight the details of the image, so that the image becomes clearer. Because Laplace is a kind of differential operator, its application can enhance the region of gray mutation in the image, and weaken the slowly changing region of gray scale.
Two, convolution algorithm 2.1 convolution principle
Therefore, the sharpening process can select the Laplace operator to process the original image, produce an image describing the gray mutation, and then overlay the Laplace image with the original image to produce sharpening images. This principle is actually convolution operation, can also be understood as an image transformation, the most common image transformation (images transform, an image to transform into an image data) is the Fourier transform (Fourier transform), will be converted to the image of the source image data of another expression, Convolution is the basis for most transformations.
We can use equations to represent this process. We first define the image as I (x, y), the nucleus is g (x, Y),
The reference point is located at the corresponding core (ai,aj) coordinates, and the convolution h (x, y) is defined as follows:
The Edge section uses copy processing, as shown in the calculation method:
2.2 OpenCV convolution function description
void Const cvarr* src, cvarr* DST, const cvmat* kernel, cvpoint chor=cvpoint (-1,-1) ); src: input image dst: Output image kernel: Convolution core, single-channel floating-point matrix. If you want to apply different cores to different channels, first use the Cvsplit function to decompose the image onto a single color channel, and then process it separately. Anchor: The anchor point of the nucleus represents the position of a filtered point within the nucleus. The anchor point should be inside the nucleus. The default value (-1,-1) represents the anchor point in the nuclear center.
In fact, using this convolution function, depending on the kernel can produce a variety of image processing, such as:
#include <iostream>#include<opencv2/highgui/highgui.hpp>#include<opencv2/core/core.hpp>#include<opencv/cv.hpp>using namespacestd; using namespaceCV; intMain () {stringPicname="lena.jpg"; Mat A=Imread (Picname,cv_load_image_color); Mat Mask= (mat_<Char> (3,3) <<0,-1,0, -1,5,-1,0,-1,0); Mat B; Filter2d (A,b,a.depth (), mask); Imshow ("A's image", A); Imshow ("image of B", B); Waitkey (); return 0; }
Three, Laplace algorithm 3.1 Laplace principle explanation
The plus operator is the simplest isotropic differential operator with rotational invariance. The Laplace transformation of a two-dimensional image function is an isotropic second-order derivative, defined as:
In a two-dimensional function f (x, Y), the second-order difference in X, y two directions is, respectively,
In order to be more suitable for digital image processing, the equation is expressed as a discrete form:
The form of a filter mask is as follows,
Note that the mask of the (a) feature, mask in the upper and lower left and right four 90 degrees in the direction of the same result, that is, in the direction of 90 degrees without directionality. In order for the mask to have this property in the direction of 45 degrees, the filter mask extension is defined as (b).
After the Laplace operator is written as filter mask, its operation is similar to other spatial filtering operations. The filter mask is moved line by row on the original image, then the value in mask is multiplied by its coincident pixels, assigned to the pixels coincident with the mask Center, and the first, and last rows and columns of the images cannot be assigned 0 of pixels of the above operation, and the result of the Laplace operation is obtained. 3.2 OpenCV Function Application
Laplacian (Src_gray, DST, ddepth, kernel_size, scale, Delta, Border_default), Src_gray, input image dst,laplace operation result Ddepth, Output image depth, because the input image is generally cv_8u, in order to avoid data overflow, the output image depth should be set to Cv_16skernel_size,filter mask size, our mask when 3x3, so here should be set to 3scale,delta, Border_default, the default setting is good
//load the Original Image and get some informationsMat src = imread ("012.jpg",0); Namedwindow ("Originalimage"); Imshow ("Originalimage", SRC); Cv_assert (src.depth ()==cv_8u);//OpenCV Solution-laplacianMat Dst,abs_dst_laplace; Laplacian (Src,dst,cv_16s,3); Convertscaleabs (dst,abs_dst_laplace);//Show the resultNamedwindow ("Result_laplacian"); Imshow ("Result_laplacian", abs_dst_laplace);
In the original image, there is a picture of the image after Laplace.
Image processing-Laplace algorithm