Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. void RegionGrowing(Mat& src, Mat& dest, int x, int y)
  2. {
  3. queue<pair<int, int> > Q;
  4. Q.push(pii(x, y));
  5. dest.at<Vec3b>(x, y)[0] = 255;
  6. int seed = ((int)src.at<Vec3b>(x, y)[0]);
  7. Mat ans = Mat::zeros(src.size(), 0);
  8. while (!Q.empty())
  9. {
  10. pii Top = Q.front();
  11. Q.pop();
  12.  
  13. for (int i = Top.first - 1; i <= Top.first + 1; i++)
  14. for (int j = Top.second - 1; j <= Top.second + 1; j++)
  15. {
  16. if (i >= 0 && i < src.rows && j>=0 && j< src.cols)
  17. {
  18. 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))
  19. {
  20. dest.at<Vec3b>(i, j)= src.at<Vec3b>(i, j);
  21. ans.at<uchar>(i, j) = 1;
  22. for (int k = i - 1; k <= i + 1; k++)
  23. for (int l = j - 1; l <= j + 1; l++)
  24. {
  25. if (k >= 0 && k < src.rows && l >= 0 && l < src.cols)
  26. {
  27. if (ans.at<uchar>(k, l) == 0)
  28. {
  29. Q.push(pii(k, l));
  30. ans.at<uchar>(k, l) = 1;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement