In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use C++ opencv image smoothing filter". In daily operation, I believe many people have doubts about how to use C++ opencv image smoothing filter. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to use C++ opencv image smoothing filter". Next, please follow the editor to study!
I. mean filtering
The normalized square filter is a very simple filter, and the output pixel value is the mean value of the pixel value in the kernel window. if the normalization processing is used, the square filtering is the mean filtering. in fact, the mean filtering is a special case after the normalization of the square filter. The mean doesn't protect the details very well.
1. Mean filter function
Opencv provides a blur function to implement mean filtering. The function declaration is as follows:
Void blur (InputArray src, OutputArray dst, Size ksize, Point anchor = Point (- 1,-1), int borderType = BORDER_DEFAULT); src input image dst output image Ksize kernel size anchor anchor default value Point (- 1,-1) indicates that the anchor is in the center of the kernel. Bordertype Boundary Pixel Mode 2. Mean filtering code # include#includeusing namespace std;using namespace cv;int main () {Mat img1, img2; img1 = imread ("cat 1.jpg"); imshow ("original image", img1); blur (img1, img2, Size (20,20)); imshow ("linear filtering", img2); waitKey (0);}
The effect is as follows:
Second, Gaussian filtering
Gaussian filtering is a kind of linear smoothing filtering, which has a good effect on removing Gaussian noise. Gaussian filtering performs convolution calculation on each point of the input array and the input Gaussian filter template, and then refines these results to form a filtered output array. The specific operation is to scan each pixel in the image with a template (or convolution, mask) and use the weighted average gray value of the pixels in the neighborhood determined by the template. To replace the value of the central pixel of the template.
1. Gaussian filtering function
Opencv provides a GaussianBlur function to implement mean filtering. The function declaration is as follows:
Void GaussianBlur (InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY = 0, int borderType = BORDER_DEFAULT); src input image dst output image ksize Gaussian kernel size they must be odd sigmax x direction is Gaussian kernel standard deviation sigmay y direction is Gaussian kernel standard deviation bordertype boundary pixel mode 2. Gaussian filtering code int main () {Mat img1, img2; img1 = imread ("cat 1.jpg"); imshow ("original image", img1); GaussianBlur (img1, img2, Size (35,35), 0); imshow ("Gaussian filtering", img2); waitKey (0);}
Effect picture:
3. Median filtering
The median filtering uses the median value of the gray value of the pixel domain to replace the gray value of the pixel, that is to say, the median value of a region is used to replace all the values, which can remove the maximum and minimum values. its advantage is that it is very useful for removing speckle noise and salt and pepper noise, but the disadvantage is that the median filtering time is more than 5 times that of the mean filter.
1. Median filter function
Opencv provides a medianBlur function to implement mean filtering. The function declaration is as follows:
Void medianBlur (InputArray src, OutputArray dst, int ksize); src input dst output Ksize aperture linear size it must be odd and greater than 12. Median filtering code int main () {Mat img1, img2; img1 = imread ("cat 1.jpg"); imshow ("original image", img1); medianBlur (img1, img2,9); imshow ("median filtering", img2); waitKey (0);}
The effect is as follows:
IV. Bilateral filtering
The filter mentioned before is to smooth the image. the problem is that sometimes these filters not only weaken the noise, but also wear off the edges. In order to avoid this situation (at least to a certain extent), we can use bilateral filtering. It is a nonlinear filter, it can achieve the effect of edge, noise reduction and smoothing, but also uses the weighted average method. The intensity of a pixel is represented by a weighted average of the luminance values of the surrounding pixels. Compared with Gaussian filtering, bilateral filtering can better preserve the edge information of the image.
1. Bilateral filter function
Opencv provides a bilateralFilter function to implement mean filtering. The function declaration is as follows:
Void bilateralFilter (InputArray src, OutputArray dst, int d, double sigmaColor, double sigmaSpace, int borderType = BORDER_DEFAULT); src input dst output diameter sigmaColor of each pixel neighborhood used in d filtering is filtered in the color space. SigmaSpace filters borderType boundary pixel mode 2 in coordinate space. Bilateral filtering codes int main () {Mat img1, img2; img1 = imread ("cat 1.jpg"); imshow ("original image", img1); bilateralFilter (img1, img2, 30jin30); imshow ("bilateral filtering", img2); waitKey (0);}
The effect is as follows:
At this point, the study of "how to use C++ opencv Image smoothing filter" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.