i.segment.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <h2>DESCRIPTION</h2>
  2. Image segmentation or object recognition is the process of grouping
  3. similar pixels into unique segments, also referred to as objects.
  4. Boundary and region based algorithms are described in the literature,
  5. currently a region growing and merging algorithm is implemented. Each
  6. object found during the segmentation process is given a unique ID and
  7. is a collection of contiguous pixels meeting some criteria. Note the
  8. contrast with image classification where all pixels similar to each
  9. other are assigned to the same class and do not need to be contiguous.
  10. The image segmentation results can be useful on their own, or used as a
  11. preprocessing step for image classification. The segmentation
  12. preprocessing step can reduce noise and speed up the classification.
  13. <h2>NOTES</h2>
  14. <h3>Region Growing and Merging</h3>
  15. This segmentation algorithm sequentially examines all current segments
  16. in the raster map. The similarity between the current segment and each
  17. of its neighbors is calculated according to the given distance
  18. formula. Segments will be merged if they meet a number of criteria,
  19. including:
  20. <ol>
  21. <li>The pair is mutually most similar to each other (the similarity
  22. distance will be smaller than to any other neighbor), and</li>
  23. <li>The similarity must be lower than the input threshold. The
  24. process is repeated until no merges are made during a complete pass.</li>
  25. </ol>
  26. <h4>Similarity and Threshold</h4>
  27. The similarity between segments and unmerged objects is used to
  28. determine which objects are merged. Smaller distance values indicate a
  29. closer match, with a similarity score of zero for identical pixels.
  30. <p>
  31. During normal processing, merges are only allowed when the
  32. similarity between two segments is lower than the given
  33. threshold value. During the final pass, however, if a minimum
  34. segment size of 2 or larger is given with the <b>minsize</b>
  35. parameter, segments with a smaller pixel count will be merged with
  36. their most similar neighbor even if the similarity is greater than
  37. the threshold.
  38. <p>
  39. The <b>threshold</b> must be larger than 0.0 and smaller than 1.0. A threshold
  40. of 0 would allow only identical valued pixels to be merged, while a
  41. threshold of 1 would allow everything to be merged. The threshold is scaled to
  42. the data range of the entire input data, not the current computational region.
  43. This allows the application of the same threshold to different computational
  44. regions when working on the same dataset, ensuring that this threshold has the
  45. same meaning in all subregions.
  46. <p>
  47. Initial empirical
  48. tests indicate threshold values of 0.01 to 0.05 are reasonable values
  49. to start. It is recommended to start with a low value, e.g. 0.01, and
  50. then perform hierarchical segmentation by using the output of the last
  51. run as <b>seeds</b> for the next run.
  52. <h4>Calculation Formulas</h4>
  53. Both Euclidean and Manhattan distances use the normal definition,
  54. considering each raster in the image group as a dimension.
  55. In future, the distance calculation will also take into account the
  56. shape characteristics of the segments. The normal distances are then
  57. multiplied by the input radiometric weight. Next an additional
  58. contribution is added: <tt>(1-radioweight) * {smoothness * smoothness
  59. weight + compactness * (1-smoothness weight)}</tt>,
  60. where <tt>compactness = Perimeter Length / sqrt( Area )</tt>
  61. and <tt>smoothness = Perimeter Length / Bounding Box</tt>. The
  62. perimeter length is estimated as the number of pixel sides the segment
  63. has.
  64. <h4>Seeds</h4>
  65. The seeds map can be used to provide either seed pixels (random or
  66. selected points from which to start the segmentation process) or
  67. seed segments. If the seeds are the results of a previous segmentation
  68. with lower threshold, hierarchical segmentation can be performed. The
  69. different approaches are automatically detected by the program: any
  70. pixels that have identical seed values and are contiguous will be
  71. assigned a unique segment ID.
  72. <h4>Maximum number of segments</h4>
  73. The current limit with CELL storage used for segment IDs is 2
  74. billion starting segment IDs. Segment IDs are assigned whenever a yet
  75. unprocessed pixel is merged with another segment. Integer overflow can
  76. happen for computational regions with more than 2 billion cells and
  77. very low threshold values, resulting in many segments. If integer
  78. overflow occurs durin region growing, starting segments can be used
  79. (created by initial classification or other methods).
  80. <h4>Goodness of Fit</h4>
  81. The <b>goodness</b> of fit for each pixel is calculated as 1 - distance
  82. of the pixel to the object it belongs to. The distance is calculated
  83. with the selected <b>similarity</b> method. A value of 1 means
  84. identical values, perfect fit, and a value of 0 means maximum possible
  85. distance, worst possible fit.
  86. <h3>Mean shift</h3>
  87. Mean shift image segmentation consists of 2 steps: anisotrophic
  88. filtering and 2. clustering. For anisotrophic filtering new cell values
  89. are calculated from all pixels not farther than <b>hs</b> pixels away
  90. from the current pixel and with a spectral difference not larger than
  91. <b>hr</b>. That means that pixels that are too different from the current
  92. pixel are not considered in the calculation of new pixel values.
  93. <b>hs</b> and <b>hr</b> are the spatial and spectral (range) bandwidths
  94. for anisotrophic filtering. Cell values are iteratively recalculated
  95. (shifted to the segment's mean) until the maximum number of iterations
  96. is reached or until the largest shift is smaller than <b>threshold</b>.
  97. <p>
  98. If input bands have been reprojected, they should not be reprojected
  99. with bilinear resampling because that method causes smooth transitions
  100. between objects. More appropriate methods are bicubic or lanczos
  101. resampling.
  102. <h3>Boundary Constraints</h3>
  103. Boundary constraints limit the adjacency of pixels and segments.
  104. Each unique value present in the <b>bounds</b> raster are
  105. considered as a MASK. Thus no segments in the final segmentated map
  106. will cross a boundary, even if their spectral data is very similar.
  107. <h3>Minimum Segment Size</h3>
  108. To reduce the salt and pepper effect, a <b>minsize</b> greater
  109. than 1 will add one additional pass to the processing. During the
  110. final pass, the threshold is ignored for any segments smaller then
  111. the set size, thus forcing very small segments to merge with their
  112. most similar neighbor. A minimum segment size larger than 1 is
  113. recommended when using adaptive bandwidth selected with the <b>-a</b>
  114. flag.
  115. <h2>EXAMPLES</h2>
  116. <h3>Segmentation of RGB orthophoto</h3>
  117. This example uses the ortho photograph included in the NC Sample
  118. Dataset. Set up an imagery group:
  119. <div class="code"><pre>
  120. i.group group=ortho_group input=ortho_2001_t792_1m@PERMANENT
  121. </pre></div>
  122. <p>Set the region to a smaller test region (resolution taken from
  123. input ortho photograph).
  124. <div class="code"><pre>
  125. g.region -p raster=ortho_2001_t792_1m n=220446 s=220075 e=639151 w=638592
  126. </pre></div>
  127. Try out a low threshold and check the results.
  128. <div class="code"><pre>
  129. i.segment group=ortho_group output=ortho_segs_l1 threshold=0.02
  130. </pre></div>
  131. <center>
  132. <img src="i_segment_ortho_segs_l1.jpg">
  133. </center>
  134. <p>
  135. From a visual inspection, it seems this results in too many segments.
  136. Increasing the threshold, using the previous results as seeds,
  137. and setting a minimum size of 2:
  138. <div class="code"><pre>
  139. i.segment group=ortho_group output=ortho_segs_l2 threshold=0.05 seeds=ortho_segs_l1 min=2
  140. i.segment group=ortho_group output=ortho_segs_l3 threshold=0.1 seeds=ortho_segs_l2
  141. i.segment group=ortho_group output=ortho_segs_l4 threshold=0.2 seeds=ortho_segs_l3
  142. i.segment group=ortho_group output=ortho_segs_l5 threshold=0.3 seeds=ortho_segs_l4
  143. </pre></div>
  144. <center>
  145. <img src="i_segment_ortho_segs_l2_l5.jpg">
  146. </center>
  147. <p>
  148. The output <tt>ortho_segs_l4</tt> with <b>threshold</b>=0.2 still has
  149. too many segments, but the output with <b>threshold</b>=0.3 has too few
  150. segments. A threshold value of 0.25 seems to be a good choice. There
  151. is also some noise in the image, lets next force all segments smaller
  152. than 10 pixels to be merged into their most similar neighbor (even if
  153. they are less similar than required by our threshold):
  154. <p>Set the region to match the entire map(s) in the group.
  155. <div class="code"><pre>
  156. g.region -p raster=ortho_2001_t792_1m@PERMANENT
  157. </pre></div>
  158. <p>
  159. Run <em>i.segment</em> on the full map:
  160. <div class="code"><pre>
  161. i.segment group=ortho_group output=ortho_segs_final threshold=0.25 min=10
  162. </pre></div>
  163. <center>
  164. <img src="i_segment_ortho_segs_final.jpg">
  165. </center>
  166. <p>
  167. Processing the entire ortho image with nearly 10 million pixels took
  168. about 450 times more then for the final run.
  169. <h3>Segmentation of panchromatic channel</h3>
  170. This example uses the panchromatic channel of the Landsat7 scene included
  171. in the North Carolina sample dataset:
  172. <div class="code"><pre>
  173. # create group with single channel
  174. i.group group=singleband input=lsat7_2002_80
  175. # set computational region to Landsat7 PAN band
  176. g.region raster=lsat7_2002_80 -p
  177. # perform segmentation with minsize=5
  178. i.segment group=singleband threshold=0.05 minsize=5 \
  179. output=lsat7_2002_80_segmented_min5 goodness=lsat7_2002_80_goodness_min5
  180. # perform segmentation with minsize=100
  181. i.segment group=singleband threshold=0.05 minsize=100
  182. output=lsat7_2002_80_segmented_min100 goodness=lsat7_2002_80_goodness_min100
  183. </pre></div>
  184. <p>
  185. <center>
  186. <img src="i_segment_lsat7_pan.png"><br>
  187. Original panchromatic channel of the Landsat7 scene
  188. </center>
  189. <p>
  190. <center>
  191. <img src="i_segment_lsat7_seg_min5.png"><br>
  192. Segmented panchromatic channel, minsize=5
  193. </center>
  194. <p>
  195. <center>
  196. <img src="i_segment_lsat7_seg_min100.png"><br>
  197. Segmented panchromatic channel, minsize=100
  198. </center>
  199. <h2>TODO</h2>
  200. <h3>Functionality</h3>
  201. <ul>
  202. <li>Further testing of the shape characteristics (smoothness,
  203. compactness), if it looks good it should be added.
  204. (<b>in progress</b>)</li>
  205. <li>Malahanobis distance for the similarity calculation.</li>
  206. </ul>
  207. <h3>Use of Segmentation Results</h3>
  208. <ul>
  209. <li>Improve the optional output from this module, or better yet, add a
  210. module for <em>i.segment.metrics</em>.</li>
  211. <li>Providing updates to <em><a href="i.maxlik.html">i.maxlik</a></em>
  212. to ensure the segmentation output can be used as input for the
  213. existing classification functionality.</li>
  214. <li>Integration/workflow for <em>r.fuzzy</em> (Addon).</li>
  215. </ul>
  216. <h3>Speed</h3>
  217. <ul>
  218. <li>See create_isegs.c</li>
  219. </ul>
  220. <h2>REFERENCES</h2>
  221. This project was first developed during GSoC 2012. Project documentation,
  222. Image Segmentation references, and other information is at the
  223. <a href="http://grasswiki.osgeo.org/wiki/GRASS_GSoC_2012_Image_Segmentation">project wiki</a>.
  224. <p>
  225. Information about
  226. <a href="http://grasswiki.osgeo.org/wiki/Image_classification">classification in GRASS</a>
  227. is at available on the wiki.
  228. <h2>SEE ALSO</h2>
  229. <em>
  230. <a href="g.gui.iclass.html">g.gui.iclass</a>,
  231. <a href="i.group.html">i.group</a>,
  232. <a href="i.maxlik.html">i.maxlik</a>,
  233. <a href="i.smap.html">i.smap</a>,
  234. <a href="r.kappa.html">r.kappa</a>
  235. </em>
  236. <h2>AUTHORS</h2>
  237. Eric Momsen - North Dakota State University<br>
  238. Markus Metz (GSoC Mentor)
  239. <p>
  240. <i>Last changed: $Date$</i>