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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 31 06:40:49 PST 2017


Author: mmetz
Date: 2017-01-31 06:40:49 -0800 (Tue, 31 Jan 2017)
New Revision: 70464

Modified:
   grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html
   grass-addons/grass7/imagery/i.superpixels.slic/main.c
Log:
i.superpixels: sync option names to i.segment, update manual

Modified: grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html	2017-01-31 10:46:24 UTC (rev 70463)
+++ grass-addons/grass7/imagery/i.superpixels.slic/i.superpixels.slic.html	2017-01-31 14:40:49 UTC (rev 70464)
@@ -5,32 +5,52 @@
 <b>k</b> option (number of superpixels) or with the <b>step</b> option 
 (distance between initial super pixel centers).
 <p>
-The <b>co</b> option controls the compactness of the resulting 
-superpixels. A larger <b>co</b> value will cause spatially more 
-compact, but also spectrally more heterogeneous superpixels. This is 
+The <b>compactness</b> option controls the compactness of the resulting 
+superpixels. A larger <b>compactness</b> value will cause spatially more 
+compact, but spectrally more heterogeneous superpixels. This is 
 the most important parameter of the module. A reasonable value should 
 be determined for small test regions before applying the module to a 
 large region.
 
 <h2>NOTES</h2>
+
+<h4>Iterations</h4>
 In each iteration, the assignment of pixels to superpixels and the 
 superpixels themselves (spatial and spectral means) are updated until 
 either the maximum number of iterations is reached or until the 
 superpixels no longer change. More iterations will provide better 
-results but will increase processing time. Recommended are about 500 
-iterations for best results (stabilized superpixels).
-<p> 
-If a minimum segment size of 2 or larger is given with the <b>min</b> 
+results but will increase processing time. The module will stop earlier 
+if convergence is reached, but it can take 1000 or more iterations 
+until convergence is reached.
+
+<h4>Minimum clump size</h4>
+If a minimum segment size of 2 or larger is given with the <b>minsize</b> 
 parameter, segments with a smaller pixel count will be merged with 
 their most similar neighbor.
-<p>
+
+<h4>Creating seeds for <em>i.segment</em></h4>
+If the purpose is to create seeds for <em>i.segment</em>, a small number 
+of iterations (at least 10) should be sufficient. Further on, a large 
+number of superpixels or a small step should be used, and small clumps 
+should not be merged.
+
+<h4>Image segmentation</h4>
+If the purpose is to perform image segmentation with 
+<em>i.superpixels.slic</em>, a larger number of iterations (e.g. 100) 
+should be used in order to obtain more stable superpixels. In this 
+case, larger superpixels can be used and small clumps can be removed 
+with the <b>minsize</b> option.
+
+<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 is 
-determined for each superpixel separately. In the next iteration, 
-spectral distances of pixels to superpixels are normalized by the 
-largest spectral distance of the current superpixel.
+zero) method. 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 
 spectral distance. For a given pixel, the normalized spectral distance 
@@ -53,6 +73,7 @@
 <a href="g.gui.iclass.html">g.gui.iclass</a>,
 <a href="i.group.html">i.group</a>, 
 <a href="i.segment.html">i.segment</a>, 
+<a href="i.clump.html">i.clump</a>, 
 <a href="i.maxlik.html">i.maxlik</a>, 
 <a href="i.smap.html">i.smap</a>, 
 <a href="r.kappa.html">r.kappa</a>

Modified: grass-addons/grass7/imagery/i.superpixels.slic/main.c
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/main.c	2017-01-31 10:46:24 UTC (rev 70463)
+++ grass-addons/grass7/imagery/i.superpixels.slic/main.c	2017-01-31 14:40:49 UTC (rev 70464)
@@ -110,7 +110,7 @@
     opt_out = G_define_standard_option(G_OPT_R_OUTPUT);
 
     opt_iteration = G_define_option();
-    opt_iteration->key = "iter";
+    opt_iteration->key = "iterations";
     opt_iteration->type = TYPE_INTEGER;
     opt_iteration->required = NO;
     opt_iteration->description = _("Maximum number of iterations");
@@ -132,7 +132,7 @@
     opt_step->answer = "0";
 
     opt_compactness = G_define_option();
-    opt_compactness->key = "co";
+    opt_compactness->key = "compactness";
     opt_compactness->type = TYPE_DOUBLE;
     opt_compactness->required = NO;
     opt_compactness->label = _("Compactness");
@@ -140,7 +140,7 @@
     opt_compactness->answer = "1";
 
     opt_minsize = G_define_option();
-    opt_minsize->key = "min";
+    opt_minsize->key = "minsize";
     opt_minsize->type = TYPE_INTEGER;
     opt_minsize->required = NO;
     opt_minsize->description = _("Minimum superpixel size");
@@ -288,7 +288,7 @@
     k_mb = k_mb * numk / (1024. * 1024.);
 
     G_debug(1, "MB for seeds: %g", k_mb);
-    if (k_mb >= segs_mb)
+    if (k_mb >= segs_mb - 10)
 	G_fatal_error(_("Not enough memory, increase %s option"), opt_mem->answer);
 
     segs_mb -= k_mb;
@@ -434,6 +434,7 @@
     invwt = 0.1 * compactness / (offset * offset);
 
     G_message(_("Performing k mean segmentation..."));
+    schange = 0;
     for (itr = 0; itr < n_iterations; itr++) {
 	G_percent(itr, n_iterations, 2);
 
@@ -588,6 +589,9 @@
 
     if (itr < n_iterations)
 	G_message(_("SLIC converged after %d iterations"), itr);
+    if (schange > 0)
+	G_verbose_message(_("%d of %d superpixels were modified in the last iteration"),
+	                  schange, numk);
 
     /* free */
 
@@ -657,6 +661,8 @@
     Rast_make_random_colors(&colors, 1, numlabels);
     Rast_write_colors(outname, G_mapset(), &colors);
 
+    G_done_msg(" ");
+
     exit(EXIT_SUCCESS);
 }
 



More information about the grass-commit mailing list