i.segment.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <h2>DESCRIPTION</h2>
  2. Image segmentation or object recognition is the process of grouping
  3. similar pixels into unique segments, also refered 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. <h3>Similarity and Threshold</h3>
  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 threshold 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. Initial empirical
  42. tests indicate threshold values of 0.01 to 0.05 are reasonable values
  43. to start. It is recommended to start with a low value, e.g. 0.01, and
  44. then perform hierachical segmentation by using the output of the last
  45. run as seeds for the next run.
  46. <h4>Calculation Formulas</h4>
  47. Both Euclidean and Manhattan distances use the normal definition,
  48. considering each raster in the image group as a dimension.
  49. In future, the distance calculation will also take into account the
  50. shape characteristics of the segments. The normal distances are then
  51. multiplied by the input radiometric weight. Next an additional
  52. contribution is added: (1-radioweight) * {smoothness * smoothness
  53. weight + compactness * (1-smoothness weight)}, where compactness =
  54. Perimeter Length / sqrt( Area ) and smoothness = Perimeter
  55. Length / Bounding Box. The perimeter length is estimated as the
  56. number of pixel sides the segment has.
  57. <h3>Seeds</h3>
  58. The seeds map can be used to provide either seed pixels (random or
  59. selected points from which to start the segmentation process) or
  60. seed segments. If the seeds are the results of a previous segmentation
  61. with lower threshold, hierarchical segmentation can be performed. The
  62. different approaches are automatically detected by the program: any
  63. pixels that have identical seed values and are contiguous will be
  64. assigned a unique segment ID.
  65. <p>
  66. It is expected that the <b>minsize</b> will be set to 1 if a seed
  67. map is used, but the program will allow other values to be used. If
  68. both options are used, the final iteration that ignores the
  69. threshold will also ignore the seed map and force merges for all
  70. pixels (not just segments that have grown/merged from the seeds).
  71. <h3>Maximum number of starting segments</h3>
  72. For the region growing algorithm without starting seeds, each pixel is
  73. sequentially numbered. The current limit with CELL storage is 2
  74. billion starting segment IDs. If the initial map has a larger number
  75. of non-null pixels, there are two workarounds:
  76. <ol>
  77. <li>Use starting seed pixels. (Maximum 2 billion pixels can be
  78. labeled with positive integers.)</li>
  79. <li>Use starting seed segments. (By initial classification or other
  80. methods.)</li>
  81. </ol>
  82. <h3>Boundary Constraints</h3>
  83. Boundary constraints limit the adjacency of pixels and segments.
  84. Each unique value present in the <b>bounds</b> raster are
  85. considered as a MASK. Thus no segments in the final segmentated map
  86. will cross a boundary, even if their spectral data is very similar.
  87. <h3>Minimum Segment Size</h3>
  88. To reduce the salt and pepper affect, a <b>minsize</b> greater
  89. than 1 will add one additional pass to the processing. During the
  90. final pass, the threshold is ignored for any segments smaller then
  91. the set size, thus forcing very small segments to merge with their
  92. most similar neighbor.
  93. <h2>EXAMPLES</h2>
  94. This example uses the ortho photograph included in the NC Sample
  95. Dataset. Set up an imagery group:
  96. <div class="code"><pre>
  97. i.group group=ortho_group input=ortho_2001_t792_1m@PERMANENT
  98. </pre></div>
  99. <p>Set the region to a smaller test region.
  100. <div class="code"><pre>
  101. g.region -p n=220446 s=220075 e=639151 w=638592
  102. </pre></div>
  103. Try out a low threshold and check the results.
  104. <div class="code"><pre>
  105. i.segment group=ortho_group output=ortho_segs_l1 threshold=0.02
  106. </pre></div>
  107. <p></p>
  108. From a visual inspection, it seems this results in too many segments.
  109. Increasing the threshold, using the previous results as seeds,
  110. and setting a minimum size of 2:
  111. <div class="code"><pre>
  112. i.segment group=ortho_group output=ortho_segs_l2 threshold=0.05 \
  113. seeds=ortho_segs_l1 min=2
  114. i.segment group=ortho_group output=ortho_segs_l3 threshold=0.1 \
  115. seeds=ortho_segs_l2
  116. i.segment group=ortho_group output=ortho_segs_l4 threshold=0.2 \
  117. seeds=ortho_segs_l3
  118. i.segment group=ortho_group output=ortho_segs_l5 threshold=0.3 \
  119. seeds=ortho_segs_l4
  120. </pre></div>
  121. <p>
  122. The output ortho_segs_l4 with threshold=0.2 still has too many segments,
  123. but the output with threshold=0.3 has too few segments. A threshold
  124. value of 0.25 seems to be a good choice. There is also some noise in
  125. the image, lets next force all segments smaller than 10 pixels to be
  126. merged into their most similar neighbor (even if they are less similar
  127. than required by our threshold):
  128. <p>Set the region to match the entire map(s) in the group.
  129. <div class="code"><pre>
  130. g.region -p rast=ortho_2001_t792_1m@PERMANENT
  131. </pre></div>
  132. <p>
  133. Run i.segment on the full map:
  134. <div class="code"><pre>
  135. i.segment group=ortho_group output=ortho_segs_final \
  136. threshold=0.25 min=10
  137. </pre></div>
  138. <p>
  139. Processing the entire ortho image with nearly 10 million pixels took
  140. about 20 minutes for the final run.
  141. <h2>TODO</h2>
  142. <h3>Functionality</h3>
  143. <ul>
  144. <li>Further testing of the shape characteristics (smoothness,
  145. compactness), if it looks good it should be added.
  146. <b>in progress</b></li>
  147. <li>Malahanobis distance for the similarity calculation.</li>
  148. </ul>
  149. <h3>Use of Segmentation Results</h3>
  150. <ul>
  151. <li>Improve the optional output from this module, or better yet, add a
  152. module for <em>i.segment.metrics</em>.</li>
  153. <li>Providing updates to <em><a href="i.maxlik.html">i.maxlik</a></em>
  154. to ensure the segmentation output can be used as input for the
  155. existing classification functionality.</li>
  156. <li>Integration/workflow for <em>r.fuzzy</em> (Addon).</li>
  157. </ul>
  158. <h3>Speed</h3>
  159. <ul>
  160. <li>See create_isegs.c</li>
  161. </ul>
  162. <h2>REFERENCES</h2>
  163. This project was first developed during GSoC 2012. Project documentation,
  164. Image Segmentation references, and other information is at the
  165. <a href="http://grass.osgeo.org/wiki/GRASS_GSoC_2012_Image_Segmentation">project wiki</a>.
  166. <p>
  167. Information about
  168. <a href="http://grass.osgeo.org/wiki/Image_classification">classification in GRASS</a>
  169. is at available on the wiki.
  170. <h2>SEE ALSO</h2>
  171. <em>
  172. <a href="i.group.html">i.group</a>,
  173. <a href="i.maxlik.html">i.maxlik</a>,
  174. <a href="r.fuzzy">r.fuzzy</a>,
  175. <a href="i.smap.html">i.smap</a>,
  176. <a href="r.seg.html">r.seg</a> (Addon)
  177. </em>
  178. <h2>AUTHORS</h2>
  179. Eric Momsen - North Dakota State University<br>
  180. Markus Metz (GSoC Mentor)