35 #include <opencv2/opencv.hpp> 36 #include "FeatureType.h" 37 #include "ContourRelaxation.h" 38 #include "InitializationFunctions.h" 56 int region_width,
double clique_cost,
double compactness,
57 int iterations,
int color_space, cv::Mat &labels) {
59 double diagonal_cost = clique_cost/std::sqrt(2);
61 bool color_image =
false;
62 if (image.channels() == 3) {
66 std::vector<FeatureType> features;
68 features.push_back(Color);
71 features.push_back(Grayvalue);
74 features.push_back(Compactness);
76 ContourRelaxation<boost::uint16_t> contour_relaxation(features);
77 contour_relaxation.setCompactnessData(compactness);
82 std::vector<cv::Mat> image_channels;
84 switch (color_space) {
87 cv::cvtColor(image, image_YCrCb, CV_BGR2YCrCb);
88 cv::split(image_YCrCb, image_channels);
91 cv::split(image, image_channels);
95 contour_relaxation.setColorData(image_channels[0], image_channels[1],
102 contour_relaxation.setGrayvalueData(image);
105 cv::Mat label_image = createBlockInitialization<boost::uint16_t>(image.size(),
106 region_width, region_height);
107 cv::Mat relaxed_label_image;
110 contour_relaxation.relax(label_image, clique_cost, diagonal_cost,
111 iterations, relaxed_label_image, mean_image);
113 labels.create(image.rows, image.cols, CV_32SC1);
114 for (
int i = 0; i < image.rows; i++) {
115 for (
int j = 0; j < image.cols; j++) {
116 labels.at<
int>(i, j) = relaxed_label_image.at<boost::uint16_t>(i, j);
Wrapper for running CRS on OpenCV images.
Definition: crs_opencv.h:43
static void computeSuperpixels(const cv::Mat &image, int region_height, int region_width, double clique_cost, double compactness, int iterations, int color_space, cv::Mat &labels)
Compute superpixels using CRS.
Definition: crs_opencv.h:55