图像修复-生成掩模图像(单通道)
#include <opencv2/opencv.hpp> #include <iostream> #include <stdlib.h> #include <math.h> #include <opencv2/highgui/highgui.hpp> #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> using namespace cv; using namespace std; int main() { Mat image, mask, result; image = imread("1234.png", 1); mask = Mat::zeros(image.size(), CV_8U); int w = image.cols; //返回图片的宽度 int h = image.rows; //返回图片的高度 for (int i = 0; i < h - 1; i++) { for (int j = 0; j < w - 1; j++) { if (image.at<cv::Vec3b>(i, j)[0] == 255 && image.at<cv::Vec3b>(i, j)[1] == 255 && image.at<cv::Vec3b>(i, j)[2] == 255) { mask.at<uchar>(i, j) = 255; } } } namedWindow("1", WINDOW_AUTOSIZE); imshow("1",mask); imwrite("1.png",mask); waitKey(0); return 0; }
转载请注明出处,欢迎讨论和交流!