1i.segment(1) Grass User's Manual i.segment(1)
2
3
4
6 i.segment - Identifies segments (objects) from imagery data.
7
9 imagery, segmentation, classification, object recognition
10
12 i.segment
13 i.segment --help
14 i.segment [-dwap] group=name output=name [band_suffix=name] thresh‐
15 old=float [radius=float] [hr=float] [method=string] [similar‐
16 ity=string] [minsize=integer] [memory=integer] [iterations=inte‐
17 ger] [seeds=name] [bounds=name] [goodness=name] [--overwrite]
18 [--help] [--verbose] [--quiet] [--ui]
19
20 Flags:
21 -d
22 Use 8 neighbors (3x3 neighborhood) instead of the default 4 neigh‐
23 bors for each pixel
24
25 -w
26 Weighted input, do not perform the default scaling of input raster
27 maps
28
29 -a
30 Use adaptive bandwidth for mean shift
31 Range (spectral) bandwidth is adapted for each moving window
32
33 -p
34 Use progressive bandwidth for mean shift
35 Spatial bandwidth is increased, range (spectral) bandwidth is
36 decreased in each iteration
37
38 --overwrite
39 Allow output files to overwrite existing files
40
41 --help
42 Print usage summary
43
44 --verbose
45 Verbose module output
46
47 --quiet
48 Quiet module output
49
50 --ui
51 Force launching GUI dialog
52
53 Parameters:
54 group=name [required]
55 Name of input imagery group
56
57 output=name [required]
58 Name for output raster map
59
60 band_suffix=name
61 Suffix for output bands with modified band values
62 Name for output raster map
63
64 threshold=float [required]
65 Difference threshold between 0 and 1
66 Threshold = 0 merges only identical segments; threshold = 1 merges
67 all
68
69 radius=float
70 Spatial radius in number of cells
71 Must be >= 1, only cells within spatial bandwidth are considered
72 for mean shift
73 Default: 1.5
74
75 hr=float
76 Range (spectral) bandwidth [0, 1]
77 Only cells within range (spectral) bandwidth are considered for
78 mean shift. Range bandwidth is used as conductance parameter for
79 adaptive bandwidth
80
81 method=string
82 Segmentation method
83 Options: region_growing, mean_shift
84 Default: region_growing
85
86 similarity=string
87 Similarity calculation method
88 Options: euclidean, manhattan
89 Default: euclidean
90
91 minsize=integer
92 Minimum number of cells in a segment
93 The final step will merge small segments with their best neighbor
94 Options: 1-100000
95 Default: 1
96
97 memory=integer
98 Memory in MB
99 Default: 300
100
101 iterations=integer
102 Maximum number of iterations
103
104 seeds=name
105 Name for input raster map with starting seeds
106
107 bounds=name
108 Name of input bounding/constraining raster map
109 Must be integer values, each area will be segmented independent of
110 the others
111
112 goodness=name
113 Name for output goodness of fit estimate map
114
116 Image segmentation or object recognition is the process of grouping
117 similar pixels into unique segments, also referred to as objects.
118 Boundary and region based algorithms are described in the literature,
119 currently a region growing and merging algorithm is implemented. Each
120 object found during the segmentation process is given a unique ID and
121 is a collection of contiguous pixels meeting some criteria. Note the
122 contrast with image classification where all pixels similar to each
123 other are assigned to the same class and do not need to be contiguous.
124 The image segmentation results can be useful on their own, or used as a
125 preprocessing step for image classification. The segmentation prepro‐
126 cessing step can reduce noise and speed up the classification.
127
129 Region Growing and Merging
130 This segmentation algorithm sequentially examines all current segments
131 in the raster map. The similarity between the current segment and each
132 of its neighbors is calculated according to the given distance formula.
133 Segments will be merged if they meet a number of criteria, including:
134
135 1 The pair is mutually most similar to each other (the similarity
136 distance will be smaller than to any other neighbor), and
137
138 2 The similarity must be lower than the input threshold. The
139 process is repeated until no merges are made during a complete
140 pass.
141
142 Similarity and Threshold
143 The similarity between segments and unmerged objects is used to deter‐
144 mine which objects are merged. Smaller distance values indicate a
145 closer match, with a similarity score of zero for identical pixels.
146
147 During normal processing, merges are only allowed when the similarity
148 between two segments is lower than the given threshold value. During
149 the final pass, however, if a minimum segment size of 2 or larger is
150 given with the minsize parameter, segments with a smaller pixel count
151 will be merged with their most similar neighbor even if the similarity
152 is greater than the threshold.
153
154 The threshold must be larger than 0.0 and smaller than 1.0. A threshold
155 of 0 would allow only identical valued pixels to be merged, while a
156 threshold of 1 would allow everything to be merged. The threshold is
157 scaled to the data range of the entire input data, not the current com‐
158 putational region. This allows the application of the same threshold
159 to different computational regions when working on the same dataset,
160 ensuring that this threshold has the same meaning in all subregions.
161
162 Initial empirical tests indicate threshold values of 0.01 to 0.05 are
163 reasonable values to start. It is recommended to start with a low
164 value, e.g. 0.01, and then perform hierarchical segmentation by using
165 the output of the last run as seeds for the next run.
166
167 Calculation Formulas
168 Both Euclidean and Manhattan distances use the normal definition, con‐
169 sidering each raster in the image group as a dimension. In future, the
170 distance calculation will also take into account the shape characteris‐
171 tics of the segments. The normal distances are then multiplied by the
172 input radiometric weight. Next an additional contribution is added:
173 (1-radioweight) * {smoothness * smoothness weight + compactness *
174 (1-smoothness weight)}, where compactness = Perimeter Length / sqrt(
175 Area ) and smoothness = Perimeter Length / Bounding Box. The perimeter
176 length is estimated as the number of pixel sides the segment has.
177
178 Seeds
179 The seeds map can be used to provide either seed pixels (random or
180 selected points from which to start the segmentation process) or seed
181 segments. If the seeds are the results of a previous segmentation with
182 lower threshold, hierarchical segmentation can be performed. The dif‐
183 ferent approaches are automatically detected by the program: any pixels
184 that have identical seed values and are contiguous will be assigned a
185 unique segment ID.
186
187 Maximum number of segments
188 The current limit with CELL storage used for segment IDs is 2 billion
189 starting segment IDs. Segment IDs are assigned whenever a yet unpro‐
190 cessed pixel is merged with another segment. Integer overflow can hap‐
191 pen for computational regions with more than 2 billion cells and very
192 low threshold values, resulting in many segments. If integer overflow
193 occurs durin region growing, starting segments can be used (created by
194 initial classification or other methods).
195
196 Goodness of Fit
197 The goodness of fit for each pixel is calculated as 1 - distance of the
198 pixel to the object it belongs to. The distance is calculated with the
199 selected similarity method. A value of 1 means identical values, per‐
200 fect fit, and a value of 0 means maximum possible distance, worst pos‐
201 sible fit.
202
203 Mean shift
204 Mean shift image segmentation consists of 2 steps: anisotrophic filter‐
205 ing and 2. clustering. For anisotrophic filtering new cell values are
206 calculated from all pixels not farther than hs pixels away from the
207 current pixel and with a spectral difference not larger than hr. That
208 means that pixels that are too different from the current pixel are not
209 considered in the calculation of new pixel values. hs and hr are the
210 spatial and spectral (range) bandwidths for anisotrophic filtering.
211 Cell values are iteratively recalculated (shifted to the segment’s
212 mean) until the maximum number of iterations is reached or until the
213 largest shift is smaller than threshold.
214
215 If input bands have been reprojected, they should not be reprojected
216 with bilinear resampling because that method causes smooth transitions
217 between objects. More appropriate methods are bicubic or lanczos resam‐
218 pling.
219
220 Boundary Constraints
221 Boundary constraints limit the adjacency of pixels and segments. Each
222 unique value present in the bounds raster are considered as a MASK.
223 Thus no segments in the final segmentated map will cross a boundary,
224 even if their spectral data is very similar.
225
226 Minimum Segment Size
227 To reduce the salt and pepper effect, a minsize greater than 1 will add
228 one additional pass to the processing. During the final pass, the
229 threshold is ignored for any segments smaller then the set size, thus
230 forcing very small segments to merge with their most similar neighbor.
231 A minimum segment size larger than 1 is recommended when using adaptive
232 bandwidth selected with the -a flag.
233
235 Segmentation of RGB orthophoto
236 This example uses the ortho photograph included in the NC Sample
237 Dataset. Set up an imagery group:
238 i.group group=ortho_group input=ortho_2001_t792_1m@PERMANENT
239
240 Set the region to a smaller test region (resolution taken from input
241 ortho photograph).
242 g.region -p raster=ortho_2001_t792_1m n=220446 s=220075 e=639151 w=638592
243 Try out a low threshold and check the results.
244 i.segment group=ortho_group output=ortho_segs_l1 threshold=0.02
245
246 From a visual inspection, it seems this results in too many segments.
247 Increasing the threshold, using the previous results as seeds, and set‐
248 ting a minimum size of 2:
249 i.segment group=ortho_group output=ortho_segs_l2 threshold=0.05 seeds=ortho_segs_l1 min=2
250 i.segment group=ortho_group output=ortho_segs_l3 threshold=0.1 seeds=ortho_segs_l2
251 i.segment group=ortho_group output=ortho_segs_l4 threshold=0.2 seeds=ortho_segs_l3
252 i.segment group=ortho_group output=ortho_segs_l5 threshold=0.3 seeds=ortho_segs_l4
253
254 The output ortho_segs_l4 with threshold=0.2 still has too many seg‐
255 ments, but the output with threshold=0.3 has too few segments. A
256 threshold value of 0.25 seems to be a good choice. There is also some
257 noise in the image, lets next force all segments smaller than 10 pixels
258 to be merged into their most similar neighbor (even if they are less
259 similar than required by our threshold):
260
261 Set the region to match the entire map(s) in the group.
262 g.region -p raster=ortho_2001_t792_1m@PERMANENT
263
264 Run i.segment on the full map:
265 i.segment group=ortho_group output=ortho_segs_final threshold=0.25 min=10
266
267 Processing the entire ortho image with nearly 10 million pixels took
268 about 450 times more then for the final run.
269
270 Segmentation of panchromatic channel
271 This example uses the panchromatic channel of the Landsat7 scene
272 included in the North Carolina sample dataset:
273 # create group with single channel
274 i.group group=singleband input=lsat7_2002_80
275 # set computational region to Landsat7 PAN band
276 g.region raster=lsat7_2002_80 -p
277 # perform segmentation with minsize=5
278 i.segment group=singleband threshold=0.05 minsize=5 \
279 output=lsat7_2002_80_segmented_min5 goodness=lsat7_2002_80_goodness_min5
280 # perform segmentation with minsize=100
281 i.segment group=singleband threshold=0.05 minsize=100
282 output=lsat7_2002_80_segmented_min100 goodness=lsat7_2002_80_goodness_min100
283
284 Original panchromatic channel of the Landsat7 scene
285
286 Segmented panchromatic channel, minsize=5
287
288 Segmented panchromatic channel, minsize=100
289
291 Functionality
292 · Further testing of the shape characteristics (smoothness, com‐
293 pactness), if it looks good it should be added. (in progress)
294
295 · Malahanobis distance for the similarity calculation.
296
297 Use of Segmentation Results
298 · Improve the optional output from this module, or better yet,
299 add a module for i.segment.metrics.
300
301 · Providing updates to i.maxlik to ensure the segmentation output
302 can be used as input for the existing classification function‐
303 ality.
304
305 · Integration/workflow for r.fuzzy (Addon).
306
307 Speed
308 · See create_isegs.c
309
311 This project was first developed during GSoC 2012. Project documenta‐
312 tion, Image Segmentation references, and other information is at the
313 project wiki.
314
315 Information about classification in GRASS is at available on the wiki.
316
318 g.gui.iclass, i.group, i.maxlik, i.smap, r.kappa
319
321 Eric Momsen - North Dakota State University
322 Markus Metz (GSoC Mentor)
323
324 Last changed: $Date: 2017-11-18 09:57:44 +0100 (Sat, 18 Nov 2017) $
325
327 Available at: i.segment source code (history)
328
329 Main index | Imagery index | Topics index | Keywords index | Graphical
330 index | Full index
331
332 © 2003-2019 GRASS Development Team, GRASS GIS 7.4.4 Reference Manual
333
334
335
336GRASS 7.4.4 i.segment(1)