search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

按照OPENCV教學文件 純C++ 範例練習紀錄 ~ [opencv_ex09-利用中值濾波medianBlur、高斯雙邊模糊bilateralFilter、最後利用提高對比度遮罩(mask)

按照OPENCV教學文件 純C++ 範例練習紀錄 ~ [opencv_ex09-利用中值濾波medianBlur、高斯雙邊模糊bilateralFilter、最後利用提高對比度遮罩(mask)運算來補強圖像]


GITHUB: https://github.com/jash-git/CPP_opencv249_ex


中值對 椒鹽噪聲(雜訊) 有很好的抑製作用

均值模糊無法克服邊緣像素信息丟失缺陷。原因是均值濾波是基於平均權重

高斯模糊部分克服了該缺陷,但是無法完全避免,因為沒有考慮像素值的不同

高斯雙邊模糊 – 是邊緣保留的濾波方法,避免了邊緣信息丟失,保留了圖像輪廓不變

#include 
#include 
#include 
#include 

#include 
#include 

#include 
#if defined(WIN32)
    #define  TIMEB    _timeb
    #define  ftime    _ftime
    typedef __int64 TIME_T;
#else
    #define TIMEB timeb
    typedef long long TIME_T;
#endif

using namespace cv;
using namespace std;
Mat src;//input image
void Pause()
{
    printf("Press Enter key to continue...");
    fgetc(stdin);
}
int main()
{
	src = imread("bgImage.jpg");
	if (!src.data)
    {
		printf("could not load image...\n");
	}
    else
    {
        Mat medianBlur;
        Mat bilateralFilter;

        namedWindow("Lena_original", CV_WINDOW_AUTOSIZE);
        imshow("Lena_original", src);

        char output_title00[] = "medianBlur";
        namedWindow(output_title00, CV_WINDOW_AUTOSIZE);
        cv::medianBlur(src, medianBlur, 3);
        imshow(output_title00, medianBlur);

        char output_title01[] = "bilateralFilter";
        cv::bilateralFilter(src, bilateralFilter, 15, 100, 5);
        //- 15 –計算的半徑,半徑之內的像數都會被納入計算,如果提供-1 則根據sigma space參數取值
        //- 150 – sigma color 決定多少差值之內的像素會被計算
        //- 3 – sigma space 如果d的值大於0則聲明無效,否則根據它來計算d值
        namedWindow(output_title01, CV_WINDOW_AUTOSIZE);
        imshow(output_title01, bilateralFilter);

        Mat resultImg00;
        Mat resultImg01;
        Mat kernel = (Mat_(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);

        filter2D(medianBlur, resultImg00, -1, kernel, Point(-1, -1), 0);
        namedWindow("medianBlur-Final Result", CV_WINDOW_AUTOSIZE);
        imshow("medianBlur-Final Result", resultImg00);


        filter2D(bilateralFilter, resultImg01, -1, kernel, Point(-1, -1), 0);
        namedWindow("bilateralFilter-Final Result", CV_WINDOW_AUTOSIZE);
        imshow("bilateralFilter-Final Result", resultImg01);
    }
    waitKey(0);
    return 0;
}


熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦