Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void regionFilling() {
- char fname[MAX_PATH];
- for (; openFileDlg(fname); ) {
- auto src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- imshow("Original Image", src);
- //vectori de directie
- int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- auto complement = complementMatrix(src);
- auto prevRes = Mat(src.size(), CV_8UC1);
- auto res = Mat(src.size(), CV_8UC1);
- for (int i = 0; i < src.rows; ++i)
- for (int j = 0; j < src.cols; ++j)
- prevRes.at<uchar>(i, j) = res.at<uchar>(i, j) = 255;
- //Find inner pixel
- bool find = false;
- for (int i = 1; i < src.rows; ++i)
- for (int j = 1; j < src.cols; ++j) {
- if (!src.at<uchar>(i, j - 1) &&
- !src.at<uchar>(i - 1, j) &&
- src.at<uchar>(i, j)) {
- res.at<uchar>(i, j) = 0;
- find = true;
- break;
- }
- if (find)
- break;
- }
- bool rtrn = false;
- //for (int k = 0; !rtrn && k == 100; ++k){
- for( ; !rtrn ; ){
- ///Conditie de iesire
- rtrn = true;
- for (int i = 0; i < src.rows; ++i)
- for (int j = 0; j < src.cols; ++j)
- if (res.at<uchar>(i, j) != prevRes.at<uchar>(i, j))
- rtrn = false;
- ///Update
- for (int i = 0; i < src.rows; ++i)
- for (int j = 0; j < src.cols; ++j)
- prevRes.at<uchar>(i, j) = res.at<uchar>(i, j);
- ///Operatii morfologice
- auto temp = dilatationMatrix(prevRes);
- res = setIntersect(temp, complement);
- }
- imshow("Result", res);
- waitKey(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement