Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
高斯模糊-灰度-拉普拉斯计算-绝对值(convertScaleAbs)-显示结果
#include
#include
#include
using namespace cv;
using namespace std;
char file[] = "1.jpg";
int main(int argc, char** argv)
{
Mat img = imread(file, -1);
pyrDown(img, img, Size(img.cols/2, img.rows/2));
imshow("1",img);
Mat gray, laplaci, final;
//高斯模糊
GaussianBlur(img, img, Size(5,5), 0, 0);
//转灰度图像
cvtColor(img, gray, CV_BGR2GRAY);
imshow("gray", gray);imwrite("gray.jpg", gray);
//拉普拉斯处理
Laplacian(gray, laplaci, CV_16S, 3, 1, 0);
//绝对值处理
convertScaleAbs(laplaci, laplaci);
//展示图像
imshow("laplaci", laplaci);imwrite("laplaci.jpg", laplaci);
//后期处理
Mat kernel = getStructuringElement(MORPH_RECT, Size(3,3), Point(-1,-1));
morphologyEx(laplaci, final, CV_MOP_TOPHAT, kernel);
threshold(final, final,100, 255, THRESH_TOZERO_INV);
threshold(final, final,20, 90, THRESH_BINARY);
imshow("final", final);imwrite("final.jpg", final);
waitKey();
return 1;
}
原图
gray
拉普拉斯
final