Sharpening is used to strengthen the edge and contour of an image, and is usually used as a high-pass filter:
The template is generally designed as a center with a positive value and a negative peripheral value (the sum of the total coefficients is 0 ):
Int main () {// source image mat scr = imread ("D:/picture/IMG. TIF "); mat rst; imshow (" Original Image ", Scr); MAT kernel (3,3, cv_32f, scalar (-1); // assign pixels to set the kernel. at <float> (1, 1) = 8; filter2d (SCR, RST, SCR. depth (), kernel); imshow ("Sharpen result", RST); waitkey (0); Return 0 ;}
We can see that although the edge is enhanced, the layers and brightness of the image are basically lost. For those smaller than 0 after calculation with the template, they will be automatically set to 0, so there will be large pieces of black.
We usually use a high-gain filter, which enhances the edge and details without losing the low-frequency components of the source image:
High Gain = a source image-low-pass = (A-1) source image + (source image * low-pass) = (A-1) source image + Qualcomm, so when a> 1, A part of the source image is added to the result of Qualcomm filter.
For a 3*3 template, the number in the center is kernel () = 9a-1, And the other number is-1.
ProgramChange only one row:
Kernel. at <float> (1, 1) = 8.9;
The results are quite different: