理论
相关API
morphologyEx(src, dst, OPT, kernel);
-Mat src: 输入图像
-Mat dst: 输出图像
-int OPT: CV_MOP_OPEN/ CV_MOP_CLOSE/ CV_MOP_GRADIENT/ CV_MOP_TOPHAT/ CV_MOP_BLACKHAT (按顺序依次为:开丶闭丶基本梯度丶顶帽丶黑帽)
-kernel: 核
代码示例
Mat src,dst;
src = imread(...);
char input_title[] = "input image";
char output_title[] = "output image";
// 先显示原图
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
// 再显示开操作之后的图
Mat kernel = getStructuringElement(MORPH_RECT, Size(11,11), Point(-1,-1));
morphologyEx(src, dst, CV_MOP_OPEN, kernel);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);
Mat src,dst;
src = imread(...);
char input_title[] = "input image";
char output_title[] = "output image";
// 先显示原图
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
// 再显示开操作之后的图
Mat kernel = getStructuringElement(MORPH_RECT, Size(11,11), Point(-1,-1));
morphologyEx(src, dst, CV_MOP_CLOSE, kernel);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);
Mat src,dst;
src = imread(...);
char input_title[] = "input image";
char output_title[] = "output image";
// 先显示原图
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
// 再显示开操作之后的图
Mat kernel = getStructuringElement(MORPH_RECT, Size(11,11), Point(-1,-1));
morphologyEx(src, dst, CV_MOP_GRADIENT, kernel);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);
Mat src,dst;
src = imread(...);
char input_title[] = "input image";
char output_title[] = "output image";
// 先显示原图
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
// 再显示开操作之后的图
Mat kernel = getStructuringElement(MORPH_RECT, Size(11,11), Point(-1,-1));
morphologyEx(src, dst, CV_MOP_TOPHAT, kernel);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);
Mat src,dst;
src = imread(...);
char input_title[] = "input image";
char output_title[] = "output image";
// 先显示原图
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
// 再显示开操作之后的图
Mat kernel = getStructuringElement(MORPH_RECT, Size(11,11), Point(-1,-1));
morphologyEx(src, dst, CV_MOP_BLACKHAT, kernel);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);