Qt 5.3 under OpenCV 2.4.11 Development (15) Filter function

Source: Internet
Author: User

The code lists Gaussian filtering, median filtering, mean filtering, and bilateral filtering:

#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp > #include <opencv2/imgproc/imgproc.hpp> #include <iostream>using namespace cv;using namespace Std;int    Main () {double duration;    Mat src = imread ("lena.jpg", 1);    Mat DST;    Namedwindow ("src", 0);    Imshow ("src", SRC);    Gaussian filtering, src: input image, DST: Output image//size (5,5) template size, for odd, x direction Variance, Y-direction variance duration = static_cast<double> (GetTickCount ());    Gaussianblur (Src,dst,size (31,31), 0,0);    Duration = static_cast<double> (GetTickCount ())-duration;    Duration/= gettickfrequency ();    cout << duration << Endl;    Namedwindow ("Gaussi", 0);    Imshow ("Gaussi", DST);    Median filter, src: input image, DST:: Output image, template width, odd duration = static_cast<double> (GetTickCount ());    Medianblur (src,dst,31);    Duration = static_cast<double> (GetTickCount ())-duration;    Duration/= gettickfrequency ();    cout << duration << Endl; Namedwindow ("MeDian ", 0);    Imshow ("Median", DST);    Mean filter, src: input image, DST: Output image, template size//point ( -1,-1): Smoothed point position, negative core center duration = static_cast<double> (GetTickCount ());    Blur (Src,dst,size (31,31), point ( -1,-1));    Duration = static_cast<double> (GetTickCount ())-duration;    Duration/= gettickfrequency ();    cout << duration << Endl;    Namedwindow ("Blur", 0);    Imshow ("Blur", DST);    Bilateral filtering, SRC: input image, DST: input image, filter template radius//color space standard deviation, coordinate space standard deviation duration = static_cast<double> (GetTickCount ());    Bilateralfilter (src,dst,31,62,31);    Duration = static_cast<double> (GetTickCount ())-duration;    Duration/= gettickfrequency ();    cout << duration << Endl;    Namedwindow ("Bilatera", 0);    Imshow ("Bilatera", DST); Waitkey (0);}

In order to facilitate the comparison, the unified use of 31 pixel size of the filter core, the results are as follows:



The results of the run time are as follows:



By comparing the filtering effect and running time, the advantages and disadvantages of various filtering algorithms are as follows:

1, mean value filter: The fastest, and not because of the increase of the filter core increases the running time, due to the special operation of the mean filter allows him to use the array to save the vector calculation method to make its operation performance and kernel size independent, the specific algorithm can see another post click Open Link, The disadvantage is that after noise reduction, the strength of some edge and detail features is reduced, and there is nothing to do with salt and pepper noise.

2, Gaussian filter: Speed relative to the mean filter slightly slower, and can not make the operating speed and the size of the filter core independent, for the normal distribution of noise has a good effect of reducing noise.

3, Median filter: The operation speed is relatively slow, and the same filter core growth rate of the premise, the operating time growth rate than the Gaussian filter algorithm is much higher growth, but for salt and pepper noise has a good filtering effect.

4, the bilateral band filter: the operation of the slowest, and in the same filter core growth rate of the premise, the operating time than median filter algorithm growth rate is also greater, but the double-band filter algorithm of the noise reduction effect is very good, because it can not only complete the noise reduction function is also good to retain the edge information in the image.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Qt 5.3 under OpenCV 2.4.11 Development (15) Filter function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.