Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void RegionGrowing(Mat& src, Mat& dest, int x, int y)
- {
- queue<pair<int, int> > Q;
- Q.push(pii(x, y));
- dest.at<Vec3b>(x, y)[0] = 255;
- int seed = ((int)src.at<Vec3b>(x, y)[0]);
- Mat ans = Mat::zeros(src.size(), 0);
- while (!Q.empty())
- {
- pii Top = Q.front();
- Q.pop();
- for (int i = Top.first - 1; i <= Top.first + 1; i++)
- for (int j = Top.second - 1; j <= Top.second + 1; j++)
- {
- if (i >= 0 && i < src.rows && j>=0 && j< src.cols)
- {
- if ((((int)src.at<Vec3b>(i, j)[0] >= ((int)src.at<Vec3b>(x, y)[0]) - 5) && ((int)src.at<Vec3b>(i, j)[0] <= ((int)src.at<Vec3b>(x, y)[0]) + 5)) && (i != Top.first && j != Top.second))
- {
- dest.at<Vec3b>(i, j)= src.at<Vec3b>(i, j);
- ans.at<uchar>(i, j) = 1;
- for (int k = i - 1; k <= i + 1; k++)
- for (int l = j - 1; l <= j + 1; l++)
- {
- if (k >= 0 && k < src.rows && l >= 0 && l < src.cols)
- {
- if (ans.at<uchar>(k, l) == 0)
- {
- Q.push(pii(k, l));
- ans.at<uchar>(k, l) = 1;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement