Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <sstream>
- void distanceTransform(int size)
- {
- std::stringstream ss;
- int rectangleSize = size / 4;
- // Create sample Mat with white rectangle
- cv::Mat data = cv::Mat::zeros(size, size, CV_8UC1);
- cv::rectangle(data, cv::Point(rectangleSize, rectangleSize), cv::Point(size - rectangleSize, size - rectangleSize), cv::Scalar::all(255), CV_FILLED);
- cv::Mat copy;
- data.copyTo(copy);
- ss << size << "-rectangle.tiff";
- cv::imwrite(ss.str(), data);
- // distance transform with [Borgefors86]
- cv::distanceTransform(data, data, CV_DIST_L2, CV_DIST_MASK_5);
- ss.str("");
- ss << size << "-borgefors86.tiff";
- cv::imwrite(ss.str(), data);
- cv::threshold(data, data, 0, 255, CV_THRESH_BINARY);
- ss.str("");
- ss << size << "-borgefors86-binary.tiff";
- cv::imwrite(ss.str(), data);
- // distance transform with [Felzenszwalb04]
- cv::distanceTransform(copy, copy, CV_DIST_L2, CV_DIST_MASK_PRECISE);
- ss.str("");
- ss << size << "-felzenszwalb04.tiff";
- cv::imwrite(ss.str(), copy);
- cv::threshold(copy, copy, 0, 255, CV_THRESH_BINARY);
- ss.str("");
- ss << size << "-felzenszwalb04-binary.tiff";
- cv::imwrite(ss.str(), copy);
- }
- int main()
- {
- distanceTransform(2500);
- distanceTransform(10000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement