Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void erode_and_dilate( cv::Mat & img) {
- cv::Mat pom = img.clone();
- int value;
- /*for (int i = 0; i< width * height; i++)
- {
- edgemap_8uc1_img.at<unsigned char>(width, height)[i]
- }*/
- for (int y = 1; y < img.cols - 1; y++) {
- for (int x = 1; x < img.rows - 1; x++) {
- value = img.at<uchar>(x, y);
- if (value == 255) {
- pom.at<uchar>(x - 1, y - 1) = 255;
- pom.at<uchar>(x - 1, y) = 255;
- pom.at<uchar>(x - 1, y + 1) = 255;
- pom.at<uchar>(x, y - 1) = 255;
- pom.at<uchar>(x, y + 1) = 255;
- pom.at<uchar>(x + 1, y - 1) = 255;
- pom.at<uchar>(x + 1, y) = 255;
- pom.at<uchar>(x + 1, y + 1) = 255;
- }
- }
- }
- for (int y = 0; y < img.cols; y++) {
- for (int x = 0; x < img.rows; x++) {
- img.at<uchar>(x, y) = pom.at<uchar>(x, y);
- }
- }
- for (int y = 1; y < img.cols - 1; y++) {
- for (int x = 1; x < img.rows - 1; x++) {
- value = img.at<uchar>(x, y);
- if (value == 255 && (
- img.at<uchar>(x - 1, y - 1) != 255 ||
- img.at<uchar>(x - 1, y) != 255 ||
- img.at<uchar>(x - 1, y + 1) != 255 ||
- img.at<uchar>(x, y - 1) != 255 ||
- img.at<uchar>(x, y + 1) != 255 ||
- img.at<uchar>(x + 1, y - 1) != 255 ||
- img.at<uchar>(x + 1, y) != 255 ||
- img.at<uchar>(x + 1, y + 1) != 255)) {
- pom.at<uchar>(x, y) = 0;
- }
- }
- }
- for (int y = 0; y < img.cols; y++) {
- for (int x = 0; x < img.rows; x++) {
- img.at<uchar>(x, y) = pom.at<uchar>(x, y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement