36 #include <opencv2/opencv.hpp> 54 bool lab,
bool perturb_seeds,
int m, cv::Mat &labels) {
56 int dx = region_width;
57 int dy = region_height;
62 CImg<> im(image.cols, image.rows, 1, 3);
63 for (
int i = 0; i < image.rows; i++) {
64 for (
int j = 0; j < image.cols; j++) {
65 im(j, i, 0, 0) = image.at<cv::Vec3b>(i, j)[0];
66 im(j, i, 0, 1) = image.at<cv::Vec3b>(i, j)[1];
67 im(j, i, 0, 2) = image.at<cv::Vec3b>(i, j)[2];
73 CImg<int> states, seeds;
83 gradient = compute_gradient(im);
86 placeSeedsOnCustomGrid2d(im.width(), im.height(), dx, dy, seeds);
89 CImg<int> perturbedSeeds;
90 if (im.depth() == 1) {
91 perturbSeeds2d(seeds, gradient, perturbedSeeds);
94 perturbSeeds3d(seeds, gradient, perturbedSeeds);
97 seeds = perturbedSeeds;
100 initialize_images(seeds, distances, states);
101 SPs = initialize_superpixels(im, seeds);
103 fmm3d(distances, seeds, states, im, SPs, m);
105 labels.create(image.rows, image.cols, CV_32SC1);
106 for (
int i = 0; i < image.rows; i++) {
107 for (
int j = 0; j < image.cols; j++) {
108 labels.at<
int>(i, j) = seeds(j, i, 0, 0);
static void computeSuperpixels(const cv::Mat &image, int region_height, int region_width, bool lab, bool perturb_seeds, int m, cv::Mat &labels)
Computer superpixels using ERGC.
Definition: ergc_opencv.h:53
Wrapper for running ERGC on OpenCV images.
Definition: ergc_opencv.h:42