According to the pixel operation method, the spatial filter can be divided into two types: linear filtering (low-pass, high-pass, and band-pass) and non-linear filtering (maximum value, minimum value, and median)
Based on the effects of image processing, smooth filtering and sharpening filtering can be performed.
The concept of linear filtering is actually borrowed from Signals and Systems. When an input signal passes through a linear system, the output result is convolution of the input signal and the system's time-domain impact response. In image processing, linear weighting is performed on pixels (and surrounding pixels) using a template. The weight is determined by the template's pixel value. The calculation method is similar to Convolution, so it is called filtering. Non-linear filtering is not a linear operation.
Because there is no formula, you may not understand the text. Here we mainly want to explain the features of these filters and how the program is implemented:
Start with the simplest mean filter today:
// Source image mat scr = imread ("D:/picture/IMG. TIF "); // result image mat RST; rst. create (SCR. rows, SCR. cols, SCR. type (); imshow ("Original Image", Scr); // mean filter function: Replace the average values of all pixels in the template with the blue R (SCR, RST, size (5, 5); imshow ("smooth filtering result", RST );
Result
When the template is changed to 10*10
Obviously, the larger the template, the blurrier the image. So if you use a filter to remove noise, the image details will also be smoothed.
You can also use the filter2d function to perform the same operation:
// Call the filter function to sharpen the image // The kernel mat kernel of the filter = mat: ones (5, 5, cv_32f)/(float) (5*5 ); // call the filter function filter2d (SCR, RST, SCR. depth (), kernel );