[GRASS-SVN] r68018 - grass-addons/grass7/imagery/i.segment.uspo
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Mar 8 02:16:26 PST 2016
Author: mlennert
Date: 2016-03-08 02:16:26 -0800 (Tue, 08 Mar 2016)
New Revision: 68018
Modified:
grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.html
grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
Log:
i.segment.uspo: indicate optimization rank in mapname, fix bug when number of segmentation maps is below nb_best + other small improvements to output and documentation
Modified: grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.html
===================================================================
--- grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.html 2016-03-08 09:44:02 UTC (rev 68017)
+++ grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.html 2016-03-08 10:16:26 UTC (rev 68018)
@@ -4,8 +4,8 @@
optimization for <em><a href="i.segment.html">i.segment</a></em>. It runs
segmentation across a user defined set of thresholds and minimum segment sizes
and then selects the parameters providing the highest values of a given
-optimization function. The number of parameter sets to provide to the user is
-defined by <b>number_best</b>.
+optimization function. The number of "best" parameter combinations to provide
+to the user per <b>region</b> is defined by <b>number_best</b>.
<p>The user provides an imagery <b>group</b> and the name of an <b>output</b>
text file where parameter and optimization values for all tested segmentations
@@ -25,19 +25,22 @@
href="https://en.wikipedia.org/wiki/Geary%27s_C">Geary's C</a>.
<p> The user can chose between hierarchical and non-hierarchical segmentation
-using the <b>n</b> flag within a given minimum segment size. The former uses <a
-href="https://grass.osgeo.org/grass70/manuals/addons/i.segment.hierarchical.html">i.segment.hierarchical</a> which uses
-each segmentation at a given threshold level as seed for the segmentation at the
-next threshold level. <p> The <b>segment_map</b> parameter allows to provide a
+using the <b>n</b> flag. The former uses each segmentation at a given threshold
+level as seed for the segmentation at the next threshold level within a given
+minimum segment size.i
+
+<p>The <b>segment_map</b> parameter allows to provide a
basename for keeping the <b>number_best</b> best segmentations for each given
<b>region</b> according to the optimization function. The resulting map names
-will be a combination of this basename, the region, the threshold and the
-minsize value.
+will be a combination of this basename, the region, the threshold, the
+minsize and the rank of the map within the region according to its optimization
+criteria value.
<p> The module uses high-level parallelisation (running different segmentations
in parallel and then running the collection of parameter values in parallel).
The parameter <b>processes</b> allows to define how many processes should be run
-in parallel.
+in parallel. Note that when using hierarchical segmentation the number of parallel
+processes is limited to the number of different mininum segment sizes to test.
<p> The <b>k</b> flag allows to keep all segmentation maps created during the
process.
@@ -77,20 +80,26 @@
G. M. Espindola , G. Camara , I. A. Reis , L. S. Bins , A. M. Monteiroi (2006),
Parameter selection for region-growing image segmentation algorithms using
spatial autocorrelation, International Journal of Remote Sensing, Vol. 27, Iss.
-14, pp. 3035-3040, http://dx.doi.org/10.1080%2f01431160600617194
+14, pp. 3035-3040, <a href="http://dx.doi.org/10.1080%2f01431160600617194">
+ http://dx.doi.org/10.1080%2f01431160600617194</a>
<br>
+<br>
B. A. Johnson, M. Bragais, I. Endo, D. B. Magcale-Macandog, P. B. M. Macandog (2015),
Image Segmentation Parameter Optimization Considering Within- and
Between-Segment Heterogeneity at Multiple Scale Levels: Test Case for Mapping
Residential Areas Using Landsat Imagery, ISPRS International Journal of
-Geo-Information, 4(4), pp. 2292-2305, http://dx.doi.org/10.3390/ijgi4042292
+Geo-Information, 4(4), pp. 2292-2305, <a href="http://dx.doi.org/10.3390/ijgi4042292">
+ http://dx.doi.org/10.3390/ijgi4042292</a>
<h2>SEE ALSO</h2>
<a href="i.segment.html">i.segment</a>,<br>
+<a href="i.group.html">i.group</a>,<br>
<a href="https://grass.osgeo.org/grass70/manuals/addons/i.segment.hierarchical.html">i.segment.hierarchical</a>,<br>
<a href="https://grass.osgeo.org/grass70/manuals/addons/r.neighborhoodmatrix.html">r.neighborhoodmatrix</a><br>
-<h2>AUTHOR</h2> Moritz Lennert
+<h2>AUTHOR</h2>
+Moritz Lennert
+
<p><i>Last changed: $Date$</i>
Modified: grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
===================================================================
--- grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py 2016-03-08 09:44:02 UTC (rev 68017)
+++ grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py 2016-03-08 10:16:26 UTC (rev 68018)
@@ -97,7 +97,7 @@
#%option
#% key: minsizes
#% type: integer
-#% description: Minimum number of cells in a segment
+#% description: Minimum number of cells in a segment to test
#% multiple: yes
#% required: no
#%end
@@ -292,7 +292,7 @@
def hierarchical_seg(parms, thresholds, minsize):
""" Do hierarchical segmentation for a vector of thresholds and a specific minsize"""
- outputs_prefix = parms['temp_segment_map'] + "_%s" % parms['region']
+ outputs_prefix = parms['temp_segment_map'] + "__%s" % parms['region']
outputs_prefix += "__%.2f"
outputs_prefix += "__%d" % minsize
previous = None
@@ -327,7 +327,7 @@
def non_hierarchical_seg(parms, threshold, minsize):
""" Do non-hierarchical segmentation for a specific threshold and minsize"""
- temp_segment_map_thresh = parms['temp_segment_map'] + "_%s" % parms['region']
+ temp_segment_map_thresh = parms['temp_segment_map'] + "__%s" % parms['region']
temp_segment_map_thresh += "__%.2f" % threshold
temp_segment_map_thresh += "__%d" % minsize
gscript.run_command('i.segment',
@@ -470,6 +470,8 @@
""" Find the nb_best values in the list of optimization function values and return their indices """
sorted_list = sorted(optlist, reverse=True)
+ if len(sorted_list) < nb_best:
+ nb_best = len(sorted_list)
opt_indices = []
for best in range(nb_best):
opt_indices.append(optlist.index(sorted_list[best]))
@@ -613,18 +615,20 @@
opt_function,
alpha,
directions[indicator])
- regiondict[region] = zip(regional_maplist, variancelist, autocorlist, optlist)
+ regiondict[region] = zip(threshlist, minsizelist, variancelist, autocorlist, optlist)
optimal_indices = find_optimal_value_indices(optlist, nb_best)
best_values[region] = []
+ rank = 1
for optind in optimal_indices:
best_values[region].append([threshlist[optind], minsizelist[optind], optlist[optind]])
- maps_to_keep.append(regional_maplist[optind])
+ maps_to_keep.append([regional_maplist[optind], rank])
+ rank += 1
# Create output
# Output of results of all attempts
- header_string = "region,threshold,minsize,variance,spatial_autocorrelation,optimization criteria\n"
+ header_string = "region,threshold,minsize,variance,spatial_autocorrelation,optimization_criteria\n"
if output == '-':
sys.stdout.write(header_string)
@@ -659,8 +663,9 @@
# Keep copies of segmentation results with best values
if segmented_map:
- for bestmap in maps_to_keep:
- outputmap = bestmap.replace(temp_segment_map, segmented_map)
+ for bestmap, rank in maps_to_keep:
+ segmented_map_name = segmented_map + "__rank%d" % rank
+ outputmap = bestmap.replace(temp_segment_map, segmented_map_name)
gscript.run_command('g.copy',
raster=[bestmap,outputmap],
quiet=True,
More information about the grass-commit
mailing list