|
| 1 | +/********************************************************************* |
| 2 | + * Software License Agreement (BSD License) |
| 3 | + * |
| 4 | + * Copyright (c) 2013 |
| 5 | + * Radhakrishna Achanta |
| 6 | + * email : Radhakrishna [dot] Achanta [at] epfl [dot] ch |
| 7 | + * web : http://ivrl.epfl.ch/people/achanta |
| 8 | + * |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions |
| 11 | + * are met: |
| 12 | + * |
| 13 | + * * Redistributions of source code must retain the above copyright |
| 14 | + * notice, this list of conditions and the following disclaimer. |
| 15 | + * * Redistributions in binary form must reproduce the above |
| 16 | + * copyright notice, this list of conditions and the following |
| 17 | + * disclaimer in the documentation and/or other materials provided |
| 18 | + * with the distribution. |
| 19 | + * * Neither the name of the copyright holders nor the names of its |
| 20 | + * contributors may be used to endorse or promote products derived |
| 21 | + * from this software without specific prior written permission. |
| 22 | + * |
| 23 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 26 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 27 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 29 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 33 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | + * POSSIBILITY OF SUCH DAMAGE. |
| 35 | + *********************************************************************/ |
| 36 | + |
| 37 | +/* |
| 38 | + "SLIC Superpixels Compared to State-of-the-art Superpixel Methods" |
| 39 | + Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, |
| 40 | + and Sabine Susstrunk, IEEE TPAMI, Volume 34, Issue 11, Pages 2274-2282, |
| 41 | + November 2012. |
| 42 | +
|
| 43 | + "SLIC Superpixels" Radhakrishna Achanta, Appu Shaji, Kevin Smith, |
| 44 | + Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk, EPFL Technical |
| 45 | + Report no. 149300, June 2010. |
| 46 | +
|
| 47 | + OpenCV port by: Cristian Balint <cristian dot balint at gmail dot com> |
| 48 | + */ |
| 49 | + |
| 50 | +#ifndef __OPENCV_SLIC_HPP__ |
| 51 | +#define __OPENCV_SLIC_HPP__ |
| 52 | +#ifdef __cplusplus |
| 53 | + |
| 54 | +#include <opencv2/core.hpp> |
| 55 | + |
| 56 | +namespace cv |
| 57 | +{ |
| 58 | +namespace ximgproc |
| 59 | +{ |
| 60 | + |
| 61 | +//! @addtogroup ximgproc_superpixel |
| 62 | +//! @{ |
| 63 | + |
| 64 | +/** @brief Class implementing the SLIC (Simple Linear Iterative Clustering) superpixels |
| 65 | +algorithm described in @cite Achanta2012. |
| 66 | +
|
| 67 | +SLIC (Simple Linear Iterative Clustering) clusters pixels using pixel channels and image plane space |
| 68 | +to efficiently generate compact, nearly uniform superpixels. The simplicity of approach makes it |
| 69 | +extremely easy to use a lone parameter specifies the number of superpixels and the efficiency of |
| 70 | +the algorithm makes it very practical. |
| 71 | +
|
| 72 | + */ |
| 73 | + |
| 74 | +class CV_EXPORTS_W SuperpixelSLIC : public Algorithm |
| 75 | +{ |
| 76 | +public: |
| 77 | + |
| 78 | + /** @brief Calculates the actual amount of superpixels on a given segmentation computed |
| 79 | + and stored in SuperpixelSLIC object. |
| 80 | + */ |
| 81 | + CV_WRAP virtual int getNumberOfSuperpixels() const = 0; |
| 82 | + |
| 83 | + /** @brief Calculates the superpixel segmentation on a given image with the initialized |
| 84 | + parameters in the SuperpixelSLIC object. |
| 85 | +
|
| 86 | + This function can be called again without the need of initializing the algorithm with |
| 87 | + createSuperpixelSLIC(). This save the computational cost of allocating memory for all the |
| 88 | + structures of the algorithm. |
| 89 | +
|
| 90 | + @param num_iterations Number of iterations. Higher number improves the result. |
| 91 | +
|
| 92 | + The function computes the superpixels segmentation of an image with the parameters initialized |
| 93 | + with the function createSuperpixelSLIC(). The algorithms starts from a grid of superpixels and |
| 94 | + then refines the boundaries by proposing updates of edges boundaries. |
| 95 | +
|
| 96 | + */ |
| 97 | + CV_WRAP virtual void iterate( int num_iterations = 10 ) = 0; |
| 98 | + |
| 99 | + /** @brief Returns the segmentation labeling of the image. |
| 100 | +
|
| 101 | + Each label represents a superpixel, and each pixel is assigned to one superpixel label. |
| 102 | +
|
| 103 | + @param labels_out Return: A CV_32SC1 integer array containing the labels of the superpixel |
| 104 | + segmentation. The labels are in the range [0, getNumberOfSuperpixels()]. |
| 105 | +
|
| 106 | + The function returns an image with the labels of the superpixel segmentation. The labels are in |
| 107 | + the range [0, getNumberOfSuperpixels()]. |
| 108 | + */ |
| 109 | + CV_WRAP virtual void getLabels( OutputArray labels_out ) const = 0; |
| 110 | + |
| 111 | + /** @brief Returns the mask of the superpixel segmentation stored in SuperpixelSLIC object. |
| 112 | +
|
| 113 | + @param image Return: CV_8U1 image mask where -1 indicates that the pixel is a superpixel border, |
| 114 | + and 0 otherwise. |
| 115 | +
|
| 116 | + @param thick_line If false, the border is only one pixel wide, otherwise all pixels at the border |
| 117 | + are masked. |
| 118 | +
|
| 119 | + The function return the boundaries of the superpixel segmentation. |
| 120 | + */ |
| 121 | + CV_WRAP virtual void getLabelContourMask( OutputArray image, bool thick_line = true ) const = 0; |
| 122 | + |
| 123 | + /** @brief Enforce label connectivity. |
| 124 | +
|
| 125 | + @param min_element_size The minimum element size in percents that should be absorbed into a bigger |
| 126 | + superpixel. Given resulted average superpixel size valid value should be in 0-100 range, 25 means |
| 127 | + that less then a quarter sized superpixel should be absorbed, this is default. |
| 128 | +
|
| 129 | + The function merge component that is too small, assigning the previously found adjacent label |
| 130 | + to this component. Calling this function may change the final number of superpixels. |
| 131 | + */ |
| 132 | + CV_WRAP virtual void enforceLabelConnectivity( int min_element_size = 25 ) = 0; |
| 133 | + |
| 134 | + |
| 135 | +}; |
| 136 | + |
| 137 | +/** @brief Class implementing the SLIC (Simple Linear Iterative Clustering) superpixels |
| 138 | +
|
| 139 | +@param image Image to segment |
| 140 | +@param algorithm Chooses the algorithm variant to use: |
| 141 | +SLIC segments image using a desired region_size, and in addition |
| 142 | +SLICO will choose an adaptive compactness factor. |
| 143 | +@param region_size Chooses an average superpixel size measured in pixels |
| 144 | +@param ruler Chooses the enforcement of superpixel smoothness factor of superpixel |
| 145 | +
|
| 146 | +The function initializes a SuperpixelSLIC object for the input image. It sets the parameters of choosed |
| 147 | +superpixel algorithm, which are: region_size and ruler. It preallocate some buffers for future |
| 148 | +computing iterations over the given image. An example of SLIC versus SLICO is ilustrated in the |
| 149 | +following picture. |
| 150 | +
|
| 151 | + |
| 152 | +
|
| 153 | + */ |
| 154 | + |
| 155 | + enum SLIC { SLIC = 100, SLICO = 101 }; |
| 156 | + |
| 157 | + CV_EXPORTS_W Ptr<SuperpixelSLIC> createSuperpixelSLIC( InputArray image, int algorithm = SLICO, |
| 158 | + int region_size = 10, float ruler = 10.0f ); |
| 159 | + |
| 160 | +//! @} |
| 161 | + |
| 162 | +} |
| 163 | +} |
| 164 | +#endif |
| 165 | +#endif |
0 commit comments