[GRASS-SVN] r70495 - grass-addons/grass7/imagery/i.superpixels.slic

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 7 01:05:16 PST 2017


Author: mlennert
Date: 2017-02-07 01:05:16 -0800 (Tue, 07 Feb 2017)
New Revision: 70495

Modified:
   grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html
   grass-addons/grass7/imagery/i.superpixels.slic/main.c
Log:
i.superpixels.slic: changed k parameter name to num_pixels, improved documentation in manual page and in code


Modified: grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html	2017-02-07 07:18:59 UTC (rev 70494)
+++ grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html	2017-02-07 09:05:16 UTC (rev 70495)
@@ -1,9 +1,10 @@
 <h2>DESCRIPTION</h2>
 
 <em>i.superpixels.slic</em> performs superpixel segmentation using a 
-k means method. The number of superpixels is determined either with the 
-<b>k</b> option (number of superpixels) or with the <b>step</b> option 
-(distance between initial super pixel centers).
+k means method, based on the work of Achanta et al. 
+The number of superpixels is determined either with the 
+<b>num_pixels</b> option (number of superpixels) or with the <b>step</b> 
+option (distance between initial super pixel centers).
 <p>
 The <b>compactness</b> option controls the compactness of the resulting 
 superpixels. A larger <b>compactness</b> value will cause spatially more 
@@ -14,6 +15,14 @@
 
 <h2>NOTES</h2>
 
+<h4>Input bands</h4>
+Contrary to the original Achanta et al. SLIC algorithm which allows only
+RGB input images (which are internally transformed into LAB color space, 
+<em>i.superpixels.slic</em> allows the use of any number of input bands. 
+These bands can be either spectral bands of imagery, or any other 
+pseudo-bands relevant to the analysis at hand (NDVI, texture, 
+precipitation, etc).
+
 <h4>Iterations</h4>
 In each iteration, the assignment of pixels to superpixels and the 
 superpixels themselves (spatial and spectral means) are updated until 
@@ -44,15 +53,21 @@
 <h4>Normalization of spectral distances (SLIC0)</h4>
 If the <b>-n</b> flag is used, the spectral distance of a pixel to a 
 given superpixel is divided by the maximum previously observed spectral 
-distance to that superpixel. This is the so-called <em>SLIC0</em> (SLIC 
-zero) method. After each iteration, the largest spectral distance to a 
+distance to that superpixel. This is an adaptation of the so-called 
+<em>SLIC0</em> (SLIC zero) method. 
+<p>
+After each iteration, the largest spectral distance to a 
 superpixel is determined from all pixels assigned to that superpixel. 
 In the next iteration, pixel assignment to superpixels is updated and 
 spectral distances of pixels to superpixels are divided by the largest 
 spectral distance of the current superpixel when evaluating a potential 
 assignment of a pixel to a superpixel.
 <p>
-That means that more heterogeneous superpixels have a larger maximum 
+Contrary to the Achanta et al. version of SLIC0, <em>i.superpixels.slic</em>
+takes into account the <em>compactness</em> value chosen by the user even
+when the <b>-n</b> flag is used.
+<p>
+SLIC0 implies that more heterogeneous superpixels have a larger maximum 
 spectral distance. For a given pixel, the normalized spectral distance 
 will be smaller for a more heterogeneous superpixel than for a more 
 homogeneous superpixel. This favours more heterogeneous superpixels 
@@ -61,7 +76,8 @@
 is smaller than to a heterogeneous pixel. As a consequence, 
 heterogeneous superpixels can become larger and and even more 
 heterogeneous. This effect becomes stronger with larger differences in 
-the spectral homogeneity of neighboring superpixels.
+the spectral homogeneity of neighboring superpixels, and with a lower
+<em>compactness</em> value, as spectral difference then gets a bigger weight.
 
 <h4>Perturbing initial superpixel centers</h4>
 Initial superpixel centers can be optimized with the <b>perturb</b> 

Modified: grass-addons/grass7/imagery/i.superpixels.slic/main.c
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/main.c	2017-02-07 07:18:59 UTC (rev 70494)
+++ grass-addons/grass7/imagery/i.superpixels.slic/main.c	2017-02-07 09:05:16 UTC (rev 70495)
@@ -122,10 +122,10 @@
     opt_iteration->answer = "10";
 
     opt_super_pixels = G_define_option();
-    opt_super_pixels->key = "k";
+    opt_super_pixels->key = "num_pixels";
     opt_super_pixels->type = TYPE_INTEGER;
     opt_super_pixels->required = NO;
-    opt_super_pixels->description = _("Number of super pixels");
+    opt_super_pixels->description = _("Approximate number of output super pixels");
     opt_super_pixels->answer = "200";
 
     opt_step = G_define_option();
@@ -484,7 +484,10 @@
     maxdistspec = maxdistspecprev = 0;
 
     offset = step;	/* offset could also be step * 1.5 */
-    /* magic factor */
+
+    /* 0.1 * compactness as this seems to give nice results for a default value of compactness = 1. */
+    /* We do not square compactness as this would make the result very sensitive to small changes   */
+    /* of compactness.										    */
     invwt = 0.1 * compactness / (offset * offset);
 
     G_message(_("Performing k mean segmentation..."));
@@ -529,7 +532,12 @@
 
 		    /* ----------------------------------------------------------------------- */
 		    distsum = dist / maxdistspeck[k] + distxy * invwt;
-		    /* dist = sqrt(dist) + sqrt(distxy*invwt);  this is more exact */
+		    /* We use a slightly different formula than that of Achanta et al.:        */
+		    /* D^2 = (dc / m)^2 + c * (ds / S)^2				       */	
+		    /* This means that m and S are always determined within the code and c is  */
+		    /* a factor to weigh the relative importance between color similarity and  */
+		    /* spatial proximity. Thus user-determined compactness is always taken     */
+		    /* into account, even in SLIC0, and is independent of the number of bands. */
 		    /*------------------------------------------------------------------------ */
 		    if (distsum < dists[1]) {
 			dists[0] = dist;



More information about the grass-commit mailing list