slic.h
Go to the documentation of this file.
00001 #ifndef SLIC_H
00002 #define SLIC_H
00003 
00004 /* slic.h.
00005  *
00006  * Written by: Pascal Mettes.
00007  *
00008  * This file contains the class elements of the class Slic. This class is an
00009  * implementation of the SLIC Superpixel algorithm by Achanta et al. [PAMI'12,
00010  * vol. 34, num. 11, pp. 2274-2282].
00011  *
00012  * This implementation is created for the specific purpose of creating
00013  * over-segmentations in an OpenCV-based environment.
00014  */
00015 
00016 #include <stdio.h>
00017 #include <math.h>
00018 #include <vector>
00019 #include <float.h>
00020 using namespace std;
00021 
00022 #include <opencv2/opencv.hpp>
00023 //using namespace cv;
00024 
00025 /* The number of iterations run by the clustering algorithm. */
00026 #define NR_ITERATIONS 10
00027 
00028 typedef cv::Vec<double, 5> Vec5d;
00029 
00030 
00031 /*
00032  * class Slic.
00033  *
00034  * In this class, an over-segmentation is created of an image, provided by the
00035  * step-size (distance between initial cluster locations) and the colour
00036  * distance parameter.
00037  */
00038 class Slic {
00039     private:
00040         
00041         /* The step size per cluster, and the colour (nc) and distance (ns)
00042          * parameters. */
00043         int step, nc, ns;
00044         
00045         /* Compute the distance between a center and an individual pixel. */
00046         double compute_dist(int ci, cv::Point pixel, cv::Vec3b colour);
00047         /* Find the pixel with the lowest gradient in a 3x3 surrounding. */
00048         cv::Point find_local_minimum(const cv::Mat_<cv::Vec3b> &image, cv::Point center);
00049         
00050         /* Remove and initialize the 2d vectors. */
00051         void clear_data();
00052         void init_data(const cv::Mat &image);
00053 
00054     public:
00055         /* Class constructors and deconstructors. */
00056         Slic();
00057         ~Slic();
00058         
00059         /* Generate an over-segmentation for an image. */
00060         void generate_superpixels(const cv::Mat &image, int step, int nc);
00061         /* Enforce connectivity for an image. */
00062         void create_connectivity(const cv::Mat &image);
00063         
00064         /* Draw functions. Resp. displayal of the centers and the contours. */
00065         void display_center_grid(cv::Mat &image, cv::Scalar colour);
00066         void display_contours(cv::Mat &image, cv::Vec3b colour);
00067         void colour_with_cluster_means(cv::Mat &image);
00068         /* The cluster assignments and distance values for each pixel. */
00069         cv::Mat_<int> clusters;
00070         cv::Mat_<double> distances;
00071         
00072         /* The LAB and xy values of the centers. */
00073         cv::Mat_<Vec5d> centers;
00074         /* The number of occurences of each center. */
00075         vector<int> center_counts;
00076 };
00077 
00078 #endif


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Tue Jul 2 2019 19:41:07