Superpixel Benchmark
Superpixel benchmark, tools and algorithms.
lsc_opencv.h
Go to the documentation of this file.
1 
32 #ifndef LSC_OPENCV_H
33 #define LSC_OPENCV_H
34 
35 #include <opencv2/opencv.hpp>
36 #include "LSC.h"
37 
41 class LSC_OpenCV {
42 public:
53  static void computeSuperpixels(const cv::Mat &image, int region_height,
54  int region_width, double ratio, int iterations, int threshold,
55  int color_space, cv::Mat &labels)
56  {
57  unsigned char* R = new unsigned char[image.rows*image.cols];
58  unsigned char* G = new unsigned char[image.rows*image.cols];
59  unsigned char* B = new unsigned char[image.rows*image.cols];
60 
61  for (int i = 0; i < image.rows; i++) {
62  for (int j = 0; j < image.cols; j++) {
63  R[i*image.cols + j] = image.at<cv::Vec3b>(i, j)[2];
64  G[i*image.cols + j] = image.at<cv::Vec3b>(i, j)[1];
65  B[i*image.cols + j] = image.at<cv::Vec3b>(i, j)[0];
66  }
67  }
68 
69  unsigned short* labeling = new unsigned short[image.rows*image.cols];
70  for (int i = 0; i < image.rows*image.cols; i++) {
71  labeling[i] = 0;
72  }
73 
74  LSC(R, G, B, image.rows, image.cols, region_height, region_width, ratio,
75  iterations, threshold, color_space, labeling);
76 
77  labels.create(image.rows, image.cols, CV_32SC1);
78  for (int i = 0; i < image.rows; i++) {
79  for (int j = 0; j < image.cols; j++) {
80  labels.at<int>(i, j) = labeling[i*image.cols + j];
81  }
82  }
83  }
84 };
85 
86 #endif /* LSC_OPENCV_H */
87 
static void computeSuperpixels(const cv::Mat &image, int region_height, int region_width, double ratio, int iterations, int threshold, int color_space, cv::Mat &labels)
Compute superpixels using LSC.
Definition: lsc_opencv.h:53
Wrapper for running LSC on OpenCV images.
Definition: lsc_opencv.h:41