1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        OpenCV中導向濾波介紹與應用

        共 3927字,需瀏覽 8分鐘

         ·

        2021-12-01 13:52

        點擊上方小白學視覺”,選擇加"星標"或“置頂

        重磅干貨,第一時間送達

        導向濾波介紹

        導向濾波是使用導向圖像作為濾波內(nèi)容圖像,在導向圖像上實現(xiàn)局部線性函數(shù)表達,實現(xiàn)各種不同的線性變換,輸出變形之后的導向濾波圖像。根據(jù)需要,導向圖像可以跟輸入圖像不同或者一致。假設(shè)I是導向圖像、p是輸入圖像、q是導向濾波輸出圖像,導向濾波是作為局部線性模型描述導向圖像I與輸出圖像q之間的關(guān)系。

        導向濾波算法實現(xiàn)的一般步驟為:

        1. 讀取導向圖像I與輸入圖像P

        2. 輸入?yún)?shù) 與 其中 表示窗口半徑大小,單位是像素, 表示模糊程度

        3. 積分圖計算I的均值與方差、輸入圖像的均值以及I與P的乘積IP

        4. 計算線性相關(guān)因子a與b

          • a=(IP-meanImeanP)/(Var_I+ )

          • b=meanP-ameanI

        5. 計算a與b的均值

        6. 使用均值得到導向濾波結(jié)果Q=meana*I+meanb

        導向濾波最常用四個功能是:

        • 邊緣保留濾波

        • 圖像去噪聲

        • 圖像邊緣羽化

        • 圖像增強(對比度)

        OpenCV中導向濾波函數(shù)

        由于導向濾波計算均值與方差可以通過積分圖查找快速得到,因此導向濾波的速度會很快,作為邊緣保留濾波它比雙線性濾波有明顯的速度優(yōu)勢,OpenCV中在擴展模塊ximgproc中實現(xiàn)了圖像的導向濾波函數(shù),相關(guān)API函數(shù)與參數(shù)解釋如下:

        1. void cv::ximgproc::guidedFilter ? ?( ?

        2. ? ?InputArray guide,// 導向圖像

        3. ? ?InputArray src,// 輸入下

        4. ? ?OutputArray dst,//導向濾波輸出

        5. ? ?int radius,//窗口半徑大小

        6. ? ?double eps,// 模糊程度

        7. ? ?int dDepth = -1// 輸出圖像深度

        8. )

        eps值越大圖像模糊程度越大、半徑radius值越大圖像模糊程度越高。

        代碼演示

        通過代碼演示了導向濾波根據(jù)輸入的導向圖像不一樣分別實現(xiàn)了圖像濾波的邊緣保留、去噪聲、羽化、對比度提升功能。完整的演示代碼如下:

        1. #include

        2. #include

        3. #include

        4. using namespace cv;

        5. using namespace cv::ximgproc;

        6. using namespace std;

        7. void guide_demo(Mat &guide, Mat &input, int r, double e);

        8. void enhance_demo(Mat &guide, Mat &input, int r, double e);

        9. int main(int argc, char** argv) {

        10. ? ?Mat src = imread("D:/vcprojects/images/guide.png");

        11. ? ?if (src.empty()) {

        12. ? ? ? ?printf("could not load image...\n");

        13. ? ? ? ?return -1;

        14. ? ?}

        15. ? ?namedWindow("input", CV_WINDOW_AUTOSIZE);

        16. ? ?imshow("input", src);

        17. ? ?namedWindow("output", CV_WINDOW_AUTOSIZE);

        18. ? ?int r = 2;

        19. ? ?double eps = 0.1;

        20. ? ?int type = 0;

        21. ? ?while (true) {

        22. ? ? ? ?char c = waitKey(50);

        23. ? ? ? ?printf("input digit : %d\n", c);

        24. ? ? ? ?if (c == 49) { // 邊緣保留

        25. ? ? ? ? ? ?type = 1;

        26. ? ? ? ?}

        27. ? ? ? ?else if (c == 50) {

        28. ? ? ? ? ? ?type = 2;

        29. ? ? ? ?}

        30. ? ? ? ?else if (c == 51) {

        31. ? ? ? ? ? ?type = 3;

        32. ? ? ? ?}

        33. ? ? ? ?else if (c == 52) { // 去噪

        34. ? ? ? ? ? ?type = 4;

        35. ? ? ? ?}

        36. ? ? ? ?else if (c == 53) { // 羽化

        37. ? ? ? ? ? ?type = 5;

        38. ? ? ? ?}

        39. ? ? ? ?else if (c == 54) { // 提升

        40. ? ? ? ? ? ?type = 6;

        41. ? ? ? ?}

        42. ? ? ? ?else if (c == 27) {

        43. ? ? ? ? ? ?break;

        44. ? ? ? ?}

        45. ? ? ? ?if (type == 0 || type == 1 || type == 2 || type == 3) {

        46. ? ? ? ? ? ?guide_demo(src, src, pow(r, type), eps*eps * pow(r, type));

        47. ? ? ? ?}

        48. ? ? ? ?else if(type == 4){

        49. ? ? ? ? ? ?Mat guide = imread("D:/vcprojects/images/gf_guide.png");

        50. ? ? ? ? ? ?Mat input = imread("D:/vcprojects/images/gf_noise.png");

        51. ? ? ? ? ? ?imshow("input", input);

        52. ? ? ? ? ? ?guide_demo(guide, input, 8, 0.02*0.02);

        53. ? ? ? ?}

        54. ? ? ? ?else if (type == 5) {

        55. ? ? ? ? ? ?Mat guide = imread("D:/vcprojects/images/twocat.png");

        56. ? ? ? ? ? ?Mat input = imread("D:/vcprojects/images/twocat_mask.png", IMREAD_GRAYSCALE);

        57. ? ? ? ? ? ?imshow("input", input);

        58. ? ? ? ? ? ?guide_demo(guide, input, 60, 10e-6);

        59. ? ? ? ?}

        60. ? ? ? ?else {

        61. ? ? ? ? ? ?Mat input = cv::imread("D:/vcprojects/images/demo.png");

        62. ? ? ? ? ? ?input.convertTo(input, CV_32F, 1.0 / 255.0);

        63. ? ? ? ? ? ?imshow("input", input);

        64. ? ? ? ? ? ?int r = 16;

        65. ? ? ? ? ? ?double eps = 0.1 * 0.1;

        66. ? ? ? ? ? ?enhance_demo(input, input, r, eps);

        67. ? ? ? ?}

        68. ? ?}

        69. ? ?waitKey(0);

        70. ? ?return 0;

        71. }

        72. void guide_demo(Mat &guide, Mat &input, int r, double e) {

        73. ? ?double eps = e * 255 * 255;

        74. ? ?Mat dst;

        75. ? ?guidedFilter(guide, input, dst, r, eps, -1);

        76. ? ?imshow("output", dst);

        77. }

        78. void enhance_demo(Mat &guide, Mat &input, int r, double e) {

        79. ? ?Mat dst;

        80. ? ?guidedFilter(guide, input, dst, r, e, -1);

        81. ? ?Mat result = (guide - dst) * 5 + dst;

        82. ? ?imshow("output", result);

        83. }

        運行截圖如下:

        邊緣保留

        去噪聲

        邊緣羽化

        對比度提升


        下載1:OpenCV-Contrib擴展模塊中文版教程
        在「小白學視覺」公眾號后臺回復:擴展模塊中文教程,即可下載全網(wǎng)第一份OpenCV擴展模塊教程中文版,涵蓋擴展模塊安裝、SFM算法、立體視覺、目標跟蹤、生物視覺、超分辨率處理等二十多章內(nèi)容。

        下載2:Python視覺實戰(zhàn)項目52講
        小白學視覺公眾號后臺回復:Python視覺實戰(zhàn)項目,即可下載包括圖像分割、口罩檢測、車道線檢測、車輛計數(shù)、添加眼線、車牌識別、字符識別、情緒檢測、文本內(nèi)容提取、面部識別等31個視覺實戰(zhàn)項目,助力快速學校計算機視覺。

        下載3:OpenCV實戰(zhàn)項目20講
        小白學視覺公眾號后臺回復:OpenCV實戰(zhàn)項目20講,即可下載含有20個基于OpenCV實現(xiàn)20個實戰(zhàn)項目,實現(xiàn)OpenCV學習進階。

        交流群


        歡迎加入公眾號讀者群一起和同行交流,目前有SLAM、三維視覺、傳感器、自動駕駛、計算攝影、檢測、分割、識別、醫(yī)學影像、GAN、算法競賽等微信群(以后會逐漸細分),請掃描下面微信號加群,備注:”昵稱+學校/公司+研究方向“,例如:”張三?+?上海交大?+?視覺SLAM“。請按照格式備注,否則不予通過。添加成功后會根據(jù)研究方向邀請進入相關(guān)微信群。請勿在群內(nèi)發(fā)送廣告,否則會請出群,謝謝理解~


        瀏覽 109
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            性爱AV免费观看 | 国产原创AV在线播放 | 大香蕉色色色 | 国产成人午夜在线观看 | 日韩欧美视频二区 | 色撸网 | 被操视频在线观看 | 男男被各种姿势c到高潮高 | 一道本高清无码视频 | 黄a毛片 精品A区 |