Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. void erode_and_dilate( cv::Mat & img) {
  2.  
  3. cv::Mat pom = img.clone();
  4.  
  5. int value;
  6. /*for (int i = 0; i< width * height; i++)
  7. {
  8. edgemap_8uc1_img.at<unsigned char>(width, height)[i]
  9. }*/
  10.  
  11. for (int y = 1; y < img.cols - 1; y++) {
  12. for (int x = 1; x < img.rows - 1; x++) {
  13. value = img.at<uchar>(x, y);
  14. if (value == 255) {
  15. pom.at<uchar>(x - 1, y - 1) = 255;
  16. pom.at<uchar>(x - 1, y) = 255;
  17. pom.at<uchar>(x - 1, y + 1) = 255;
  18. pom.at<uchar>(x, y - 1) = 255;
  19. pom.at<uchar>(x, y + 1) = 255;
  20. pom.at<uchar>(x + 1, y - 1) = 255;
  21. pom.at<uchar>(x + 1, y) = 255;
  22. pom.at<uchar>(x + 1, y + 1) = 255;
  23. }
  24. }
  25. }
  26. for (int y = 0; y < img.cols; y++) {
  27. for (int x = 0; x < img.rows; x++) {
  28. img.at<uchar>(x, y) = pom.at<uchar>(x, y);
  29. }
  30. }
  31.  
  32. for (int y = 1; y < img.cols - 1; y++) {
  33. for (int x = 1; x < img.rows - 1; x++) {
  34. value = img.at<uchar>(x, y);
  35. if (value == 255 && (
  36. img.at<uchar>(x - 1, y - 1) != 255 ||
  37. img.at<uchar>(x - 1, y) != 255 ||
  38. img.at<uchar>(x - 1, y + 1) != 255 ||
  39. img.at<uchar>(x, y - 1) != 255 ||
  40. img.at<uchar>(x, y + 1) != 255 ||
  41. img.at<uchar>(x + 1, y - 1) != 255 ||
  42. img.at<uchar>(x + 1, y) != 255 ||
  43. img.at<uchar>(x + 1, y + 1) != 255)) {
  44. pom.at<uchar>(x, y) = 0;
  45.  
  46. }
  47. }
  48. }
  49. for (int y = 0; y < img.cols; y++) {
  50. for (int x = 0; x < img.rows; x++) {
  51. img.at<uchar>(x, y) = pom.at<uchar>(x, y);
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement