36 #include <opencv2/opencv.hpp> 54 double weight_length,
int radius,
int num_nei_cluster,
55 int num_direct_nei,
int threshold, cv::Mat &labels) {
59 VCells vc(superpixels, weight_length);
61 vc.bmpWidth = image.cols;
62 vc.bmpHeight = image.rows;
63 vc.lineByte = vc.bmpWidth;
66 struct pixel* pixelArray =
new pixel[vc.bmpHeight*vc.bmpWidth];
67 for (
int i = 0; i < vc.bmpHeight; i++) {
68 for (
int j = 0; j < vc.bmpWidth; j++) {
69 int index = vc.getIndexFromRC(i, j);
70 pixelArray[index].color[0] = image.at<cv::Vec3b>(i, j)[0];
71 pixelArray[index].color[1] = image.at<cv::Vec3b>(i, j)[1];
72 pixelArray[index].color[2] = image.at<cv::Vec3b>(i, j)[2];
79 struct centroid* generators =
new centroid[superpixels];
80 vc.initializePixel(pixelArray);
81 vc.initializeGenerators(generators, pixelArray);
82 vc.classicCVT(pixelArray, generators);
87 vc.EWCVT(generators, pixelArray);
89 labels.create(image.rows, image.cols, CV_32SC1);
90 for (
int i = 0; i < vc.bmpHeight; i++) {
91 for (
int j = 0; j < vc.bmpWidth; j++) {
92 int index = vc.getIndexFromRC(i, j);
93 labels.at<
int>(i, j) = pixelArray[index].indexCluster;
static void computeSuperpixels(const cv::Mat &image, int superpixels, double weight_length, int radius, int num_nei_cluster, int num_direct_nei, int threshold, cv::Mat &labels)
Compute superpixels using VC.
Definition: vc_opencv.h:53
Wrapper for running VC on OpenCV images.
Definition: vc_opencv.h:41