影象演算法之六:特徵提取演算法之LoG
阿新 • • 發佈:2019-01-27
1、產生:
Laplace運算元對通過影象進行操作實現邊緣檢測的時,對離散點和噪聲比較敏感。於是,首先對影象進行高斯暖卷積濾波進行降噪處理,再採用Laplace運算元進行邊緣檢測,就可以提高運算元對噪聲和離散點的Robust,
這一個過程中Laplacian of Gaussian(LOG)運算元就誕生了。
:
3、演算法實現
實驗效果:
2、基本理論
高斯卷積函式定義為:
而原始影象與高斯卷積定義為:
因為:
所以Laplacian of Gaussian(LOG)可以通過先對高斯函式進行偏導操作,然後進行卷積求解。公式表示為:
和
因此,我們可以LOG核函式定義為
Laplacian of Gaussian計算可以利用高斯差分來近似,其中差分是由兩個高斯濾波與不同變數的卷積結果求得的。
3、演算法實現
#include<iostream> #include<opencv2/opencv.hpp> #include<features2d/features2d.hpp> #include<opencv2/objdetect/objdetect.hpp> #include"opencv2/imgproc/imgproc.hpp" usingnamespace std; usingnamespace cv; intmain(intargc,char**argv) { Matimg = imread("bear.jpg"); if(img.empty()) { std::cout<< "You didn't read the image sucessfully!" << std::endl; return0; } namedWindow("src"); imshow("src", img); waitKey(20); MatimgGaussian,img16S,imgLoG,imgSobelx,imgSobely,imgSobel,imgCanny; GaussianBlur(img, imgGaussian,Size(3, 3),1);//高斯模糊 namedWindow("Gaussian"); imshow("Gaussian", imgGaussian); waitKey(0); Laplacian(imgGaussian, img16S, 3); convertScaleAbs(img16S,imgLoG,1); namedWindow("LoG"); imshow("LoG", imgLoG); waitKey(0); Sobel(img, img16S, 3, 1, 0); convertScaleAbs(img16S, imgSobelx, 1); Sobel(img, img16S, 3, 0, 1); convertScaleAbs(img16S, imgSobely, 1); add(imgSobelx, imgSobely, imgSobel); namedWindow("Sobel"); imshow("Sobel", imgSobel); waitKey(0); Canny(img, imgCanny, 100, 200); namedWindow("Canny"); imshow("Canny", imgCanny); waitKey(0); return0; }
實驗效果: