<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FEmomsen</id>
	<title>GRASS-Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FEmomsen"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FEmomsen"/>
	<updated>2026-05-26T09:07:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=User:Emomsen&amp;diff=16765</id>
		<title>User:Emomsen</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=User:Emomsen&amp;diff=16765"/>
		<updated>2012-10-30T14:14:15Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: Created page with &amp;quot;GRASS user, first code contribution was [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment] for GSoC 2012.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;GRASS user, first code contribution was [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment] for GSoC 2012.&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=PSC_election_2012&amp;diff=16764</id>
		<title>PSC election 2012</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=PSC_election_2012&amp;diff=16764"/>
		<updated>2012-10-30T14:11:34Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: Added nomination for Moritz&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== List of nominees for the [[PSC]] election ===&lt;br /&gt;
&lt;br /&gt;
'''Any community member is eligible to propose a new PSC member candidate.'''&lt;br /&gt;
&lt;br /&gt;
To submit a PSC member nomination: &lt;br /&gt;
* Please confirm with the nominated person first.&lt;br /&gt;
* Please send an email to PSC mailing list - grass-psc@lists.osgeo.org (you should be subscribed) - and also feel free to cc: the nomination to the GRASS user list - grass-user@lists.osgeo.org - so that the community remains informed.&lt;br /&gt;
* Please add details below.&lt;br /&gt;
* Also, you might want to reference your Wiki profile here:&lt;br /&gt;
&lt;br /&gt;
Deadline: [http://www.timeanddate.com/worldclock/fixedtime.html?year=2012&amp;amp;month=10&amp;amp;day=31&amp;amp;hour=12&amp;amp;min=0&amp;amp;sec=0 Wednesday, 31 October 2012, 12:00 UTC]&lt;br /&gt;
&lt;br /&gt;
The list of nominees:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!Country&lt;br /&gt;
!Notes&lt;br /&gt;
&amp;lt;!-- ++++++++++++ Nothing to change above +++++++++++ --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|'''Candidate's name'''&lt;br /&gt;
|'''Country'''&lt;br /&gt;
|From: '''Your name (Nominator)'''&lt;br /&gt;
&lt;br /&gt;
I'd like to nominate XXX&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|''Martin Landa''&lt;br /&gt;
|''Czech Republic''&lt;br /&gt;
|From: ''[[User:Madi|Margherita Di Leo]]''&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/grass-psc/2012-October/000936.html]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|''Markus Metz''&lt;br /&gt;
|''Germany''&lt;br /&gt;
|From: ''[[User:lucadelu|Luca Delucchi]]''&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/grass-psc/2012-October/000937.html]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|''Margherita Di Leo''&lt;br /&gt;
|''Italy''&lt;br /&gt;
|From: ''[[User:Hellik|Helmut Kudrnovsky]]''&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/grass-user/2012-October/065859.html]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|''Moritz Lennert''&lt;br /&gt;
|''Belgium''&lt;br /&gt;
|From: ''[[User:Emomsen|Eric Momsen]]''&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/grass-psc/2012-October/000952.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
 ''Please copy this section to add new nominees''&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|''Name''&lt;br /&gt;
|''Country''&lt;br /&gt;
|From: ''Nominator''&lt;br /&gt;
&lt;br /&gt;
''Free text to introduce the nominee''&lt;br /&gt;
&lt;br /&gt;
* [0] ''Add some links''&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:PSC]]&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16351</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16351"/>
		<updated>2012-08-20T15:13:43Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* ToDo List */ finalized list.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation [http://lists.osgeo.org/pipermail/soc/2012-June/001854.html Report 5]&lt;br /&gt;
* Week 6: Validation  [http://lists.osgeo.org/pipermail/soc/2012-June/001879.html Report 6]&lt;br /&gt;
* Week 7: Debugging [http://lists.osgeo.org/pipermail/soc/2012-July/001898.html Report 7]&lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. [http://lists.osgeo.org/pipermail/soc/2012-July/001921.html Report 8]&lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/soc/2012-July/001941.html Report 9], [http://lists.osgeo.org/pipermail/soc/2012-July/001960.html Report 10], [http://lists.osgeo.org/pipermail/soc/2012-August/001986.html Report 11], [http://lists.osgeo.org/pipermail/soc/2012-August/002002.html Report 12], [http://lists.osgeo.org/pipermail/soc/2012-August/002041.html Report 13]&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
The list has been updated for the status at the end of GSoC 2012.  Remaining items to be developed later are added to the TODO manual section.  Further progress and new features requests will not be added to this listing.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&amp;lt;/del&amp;gt; implemented.  No significant time change on the small maps it was tested on.  Probably this will be helpful if disk I/O becomes limiting.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&amp;lt;/del&amp;gt; Decided not to change this.&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&amp;lt;/del&amp;gt; Implemented&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&amp;lt;/del&amp;gt; Added some additional checks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&amp;lt;/del&amp;gt; Resolved most.  Some are left as enhancement suggestions for later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&amp;lt;/del&amp;gt; Using % complete of the input number of passes threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: GUI (to combine i.segment with the stats module)&amp;lt;/del&amp;gt; Wait until there is user demand for this.&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16350</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16350"/>
		<updated>2012-08-20T15:11:48Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Polish */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation [http://lists.osgeo.org/pipermail/soc/2012-June/001854.html Report 5]&lt;br /&gt;
* Week 6: Validation  [http://lists.osgeo.org/pipermail/soc/2012-June/001879.html Report 6]&lt;br /&gt;
* Week 7: Debugging [http://lists.osgeo.org/pipermail/soc/2012-July/001898.html Report 7]&lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. [http://lists.osgeo.org/pipermail/soc/2012-July/001921.html Report 8]&lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/soc/2012-July/001941.html Report 9], [http://lists.osgeo.org/pipermail/soc/2012-July/001960.html Report 10], [http://lists.osgeo.org/pipermail/soc/2012-August/001986.html Report 11], [http://lists.osgeo.org/pipermail/soc/2012-August/002002.html Report 12], [http://lists.osgeo.org/pipermail/soc/2012-August/002041.html Report 13]&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&amp;lt;/del&amp;gt; implemented.  No significant time change on the small maps it was tested on.  Probably this will be helpful if disk I/O becomes limiting.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&amp;lt;/del&amp;gt; Decided not to change this.&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&amp;lt;/del&amp;gt; Implemented&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&amp;lt;/del&amp;gt; Added some additional checks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&amp;lt;/del&amp;gt; Resolved most.  Some are left as enhancement suggestions for later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&amp;lt;/del&amp;gt; Using % complete of the input number of passes threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: GUI (to combine i.segment with the stats module)&amp;lt;/del&amp;gt; Wait until there is user demand for this.&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16349</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16349"/>
		<updated>2012-08-20T15:11:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Polish */ Updated list&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation [http://lists.osgeo.org/pipermail/soc/2012-June/001854.html Report 5]&lt;br /&gt;
* Week 6: Validation  [http://lists.osgeo.org/pipermail/soc/2012-June/001879.html Report 6]&lt;br /&gt;
* Week 7: Debugging [http://lists.osgeo.org/pipermail/soc/2012-July/001898.html Report 7]&lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. [http://lists.osgeo.org/pipermail/soc/2012-July/001921.html Report 8]&lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/soc/2012-July/001941.html Report 9], [http://lists.osgeo.org/pipermail/soc/2012-July/001960.html Report 10], [http://lists.osgeo.org/pipermail/soc/2012-August/001986.html Report 11], [http://lists.osgeo.org/pipermail/soc/2012-August/002002.html Report 12], [http://lists.osgeo.org/pipermail/soc/2012-August/002041.html Report 13]&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&amp;lt;/del&amp;gt; implemented.  No significant time change on the small maps it was tested on.  Probably this will be helpful if disk I/O becomes limiting.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&amp;lt;/del&amp;gt; Decided not to change this.&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&amp;lt;/del&amp;gt; Implemented&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&amp;lt;/del&amp;gt; Added some additional checks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&amp;lt;del&amp;gt; Resolved most.  Some are left as enhancement suggestions for later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&amp;lt;/del&amp;gt; Using % complete of the input number of passes threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: GUI (to combine i.segment with the stats module)&amp;lt;/del&amp;gt; Wait until there is user demand for this.&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16348</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16348"/>
		<updated>2012-08-20T15:09:09Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Memory */  Updated list&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation [http://lists.osgeo.org/pipermail/soc/2012-June/001854.html Report 5]&lt;br /&gt;
* Week 6: Validation  [http://lists.osgeo.org/pipermail/soc/2012-June/001879.html Report 6]&lt;br /&gt;
* Week 7: Debugging [http://lists.osgeo.org/pipermail/soc/2012-July/001898.html Report 7]&lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. [http://lists.osgeo.org/pipermail/soc/2012-July/001921.html Report 8]&lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/soc/2012-July/001941.html Report 9], [http://lists.osgeo.org/pipermail/soc/2012-July/001960.html Report 10], [http://lists.osgeo.org/pipermail/soc/2012-August/001986.html Report 11], [http://lists.osgeo.org/pipermail/soc/2012-August/002002.html Report 12], [http://lists.osgeo.org/pipermail/soc/2012-August/002041.html Report 13]&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&amp;lt;/del&amp;gt; implemented.  No significant time change on the small maps it was tested on.  Probably this will be helpful if disk I/O becomes limiting.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&amp;lt;/del&amp;gt; Decided not to change this.&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&amp;lt;/del&amp;gt; Decided not to do this.&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&amp;lt;/del&amp;gt; Implemented&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16347</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16347"/>
		<updated>2012-08-20T15:08:21Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Speed */ updated list&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation [http://lists.osgeo.org/pipermail/soc/2012-June/001854.html Report 5]&lt;br /&gt;
* Week 6: Validation  [http://lists.osgeo.org/pipermail/soc/2012-June/001879.html Report 6]&lt;br /&gt;
* Week 7: Debugging [http://lists.osgeo.org/pipermail/soc/2012-July/001898.html Report 7]&lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. [http://lists.osgeo.org/pipermail/soc/2012-July/001921.html Report 8]&lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/soc/2012-July/001941.html Report 9], [http://lists.osgeo.org/pipermail/soc/2012-July/001960.html Report 10], [http://lists.osgeo.org/pipermail/soc/2012-August/001986.html Report 11], [http://lists.osgeo.org/pipermail/soc/2012-August/002002.html Report 12], [http://lists.osgeo.org/pipermail/soc/2012-August/002041.html Report 13]&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&amp;lt;/del&amp;gt; implemented.  No significant time change on the small maps it was tested on.  Probably this will be helpful if disk I/O becomes limiting.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&amp;lt;/del&amp;gt; Decided not to change this.&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16346</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16346"/>
		<updated>2012-08-20T15:05:56Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Project Plan */ Added links to reports.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation [http://lists.osgeo.org/pipermail/soc/2012-June/001854.html Report 5]&lt;br /&gt;
* Week 6: Validation  [http://lists.osgeo.org/pipermail/soc/2012-June/001879.html Report 6]&lt;br /&gt;
* Week 7: Debugging [http://lists.osgeo.org/pipermail/soc/2012-July/001898.html Report 7]&lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. [http://lists.osgeo.org/pipermail/soc/2012-July/001921.html Report 8]&lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
[http://lists.osgeo.org/pipermail/soc/2012-July/001941.html Report 9], [http://lists.osgeo.org/pipermail/soc/2012-July/001960.html Report 10], [http://lists.osgeo.org/pipermail/soc/2012-August/001986.html Report 11], [http://lists.osgeo.org/pipermail/soc/2012-August/002002.html Report 12], [http://lists.osgeo.org/pipermail/soc/2012-August/002041.html Report 13]&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16305</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16305"/>
		<updated>2012-08-15T17:58:30Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Functionality */  updated completed tasks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Starting seed pixels for the segments&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: handle null cells in the optional boundary constraints raster.&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&amp;lt;/del&amp;gt; (documented limitation)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (&amp;lt;del&amp;gt;Manhattan&amp;lt;/del&amp;gt;, Malahanobis)  (Added Manhattan distance)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16225</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16225"/>
		<updated>2012-07-24T14:02:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Speed */  crossed off two items&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
1: Starting seed pixels for the segments&lt;br /&gt;
&lt;br /&gt;
1: handle null cells in the optional boundary constraints raster.&lt;br /&gt;
&lt;br /&gt;
2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (Manhattan, Malahanobis)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&amp;lt;/del&amp;gt; implemented, ~20% speed reduction&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&amp;lt;/del&amp;gt; TODO: need to decide if this should stay in or out, or as an option.  Currently implemented as an option.  Need to do some speed tests to see if it is faster or slower after finishing some other changes.&lt;br /&gt;
&lt;br /&gt;
2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16191</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16191"/>
		<updated>2012-07-17T18:32:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Functionality */ implemented 8 neighbors&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;del&amp;gt;1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&amp;lt;/del&amp;gt; (done)&lt;br /&gt;
&lt;br /&gt;
1: Starting seed pixels for the segments&lt;br /&gt;
&lt;br /&gt;
1: handle null cells in the optional boundary constraints raster.&lt;br /&gt;
&lt;br /&gt;
2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (Manhattan, Malahanobis)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&lt;br /&gt;
&lt;br /&gt;
2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&lt;br /&gt;
&lt;br /&gt;
2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16190</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16190"/>
		<updated>2012-07-17T18:28:54Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Memory */  lowered priority on taking seg id out of RAM.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&lt;br /&gt;
&lt;br /&gt;
1: Starting seed pixels for the segments&lt;br /&gt;
&lt;br /&gt;
1: handle null cells in the optional boundary constraints raster.&lt;br /&gt;
&lt;br /&gt;
2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (Manhattan, Malahanobis)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&lt;br /&gt;
&lt;br /&gt;
2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&lt;br /&gt;
&lt;br /&gt;
2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
3: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?) (Only consider if we run into RAM limitations.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.group}}&lt;br /&gt;
* i.segment&lt;br /&gt;
* {{cmd|r.to.vect}}&lt;br /&gt;
* i.segment.metrics and/or {{cmd|i.maxlik}} and/or {{AddonCmd|r.fuzzy}}&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= Results =&lt;br /&gt;
&lt;br /&gt;
== Ortho-photo ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to ortho data is missing] has 3 bands, and the computational region is 1,120,080 cells, at 1-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=ortho output=ortho_segs_ha threshold=0.02 endt=10000 final_mean=ortho_segs_mean_ha min=20 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 22m53.255s on a Intel i5 laptop with 4Go RAM. The memory consumption was around 38 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Raglan_ortho_seg.png]]&lt;br /&gt;
&lt;br /&gt;
== SPOT5 scene ==&lt;br /&gt;
&lt;br /&gt;
The [http://grass.osgeo.org/wiki/where_are_these_data link to SPOT data is missing] has 4 bands, and the computational region is 4,444,517 cells, at 10-m resolution.&lt;br /&gt;
&lt;br /&gt;
Here's the code used to generate this segmentation result:&lt;br /&gt;
&lt;br /&gt;
i.segment group=spot output=spot_seg threshold=0.01 endt=10000 min=30 --o&lt;br /&gt;
&lt;br /&gt;
The segmentation performed in 87m3.870s on a Intel Core 2 workstation with 8Go RAM. The memory consumption was around 170 Mo.&lt;br /&gt;
&lt;br /&gt;
[[File:Taranaki spot seg.png]]&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16097</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16097"/>
		<updated>2012-07-10T20:36:20Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Speed */  - added peano ordering&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&lt;br /&gt;
&lt;br /&gt;
1: Starting seed pixels for the segments&lt;br /&gt;
&lt;br /&gt;
1: handle null cells in the optional boundary constraints raster.&lt;br /&gt;
&lt;br /&gt;
2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (Manhattan, Malahanobis)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&lt;br /&gt;
&lt;br /&gt;
2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&lt;br /&gt;
&lt;br /&gt;
2: Consider peano or other ordering for pixel processing (instead of row major order), should help processing time if an entire &amp;quot;row&amp;quot; of segments are not in RAM.&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?)&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* i.group&lt;br /&gt;
* i.segment&lt;br /&gt;
* r.to.vect&lt;br /&gt;
* i.segment.metrics and/or i.maxlik and/or r.fuzzy&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16096</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=16096"/>
		<updated>2012-07-10T16:11:58Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: Added ToDo list&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= ToDo List =&lt;br /&gt;
&lt;br /&gt;
The following list was developed at the &amp;quot;mid&amp;quot; point review, with about 1 month left.  Rating system is 1: must do, 2: would be nice, 3: probably only will be finished if it is a quick task.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
1: Implement the 8 neighbor option (currenly only the 4 pixel neighbors are considered).&lt;br /&gt;
&lt;br /&gt;
1: Starting seed pixels for the segments&lt;br /&gt;
&lt;br /&gt;
1: handle null cells in the optional boundary constraints raster.&lt;br /&gt;
&lt;br /&gt;
2: Current input limit is 2 billion starting segments, constrained by &amp;quot;int&amp;quot; data type for segment ID.  Consider long int, and/or dynamic allocation of different storage depending on what is needed. (MM: Unfortunately you are stuck with the largest integer type that a GRASS raster supports with is 32 bit integer. Internally you could use larger integer types, but then you can not save the results... EM: Hmm, if the segments are renumbered sequenctial at the end, it would be possible to then save them if the resulting number of segments is less then 2 billion...  Does anyone want to segment a raster with more than 2 billion pixels?  As a work around, larger maps could be processed, if a random selection of pixels are used as seeds... At a minimum, put this limitation in as error checking and the documents.)&lt;br /&gt;
&lt;br /&gt;
2: Check input parameters for mean-shift and other segmentation algorithms, try to make input parameters &amp;quot;generic&amp;quot; so they could be used for any/other algorithms.&lt;br /&gt;
&lt;br /&gt;
2: Add shape characteristics (smoothness, compactness) to the similarity measurement. Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;.  Check Baatz and Shape paper.  Adds two input parameters (weight of radiometric to shape, and weight of compactness to smoothness.) (Maybe use the ratio of the number of edge cells to the total number of cells as a proxy for compactness, which could be easily obtained as a side-product when finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
2: Alternate similarity measurements (Manhattan, Malahanobis)&lt;br /&gt;
&lt;br /&gt;
3: Adding a parameter to make it easier to merge smaller segments and harder to merge large segments. (Preliminary testing is not promising, low priority)&lt;br /&gt;
&lt;br /&gt;
3: Estimating the threshold value. (at least add to docs) (1 to 5% of the max difference gave me (MM) subjectively good results.)&lt;br /&gt;
&lt;br /&gt;
?: Adding control for what scale the segmentation is performed at.  (EM: I'm not certain what is meant/needed for this, but I think it is a different concept from just using g.region.)&lt;br /&gt;
&lt;br /&gt;
== Statistics/metrics ==&lt;br /&gt;
&lt;br /&gt;
1: i.segment.stats&lt;br /&gt;
(It should do more then just statistics...  .evaluation .metrics .data  Maybe i.segment.metrics?)&lt;br /&gt;
(Will need to evaulate what is already available from other GRASS modules, what is easy, what is hard.  Start from the specifications for what is desired.)&lt;br /&gt;
&lt;br /&gt;
1: Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality.&lt;br /&gt;
&lt;br /&gt;
1: Integration/workflow for r.fuzzy.&lt;br /&gt;
&lt;br /&gt;
== Speed ==&lt;br /&gt;
&lt;br /&gt;
2: Neighbor finding, keep a tree structure of found neighbor segments to reduce the number of neighbor pixels that the similarity function will be run on.&lt;br /&gt;
&lt;br /&gt;
2: Search continuation.  If Ri isn't Rk's best neighbor, then use Rk as the next Ri.  (Skips one neighbor finding routine.)&lt;br /&gt;
&lt;br /&gt;
3: neighbor finding: When checking for Rk's neighbors, account for already knowing Ri and skip those pixels.&lt;br /&gt;
&lt;br /&gt;
?: change candidate flag to int (compare with pass number) to avoid resetting each time. (32x RAM requirement for the flag, is it worth it?)&lt;br /&gt;
&lt;br /&gt;
?: RAM storage of the segment membership and the neighboring segments (calculate first the requirements, if this is even possible for reasonable (what size?) maps).  (check what % of the processing time is spent finding neighbors.)&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
1: Put segment ID in SEG instead of RAM. (Possibly make this dependent on available RAM?)&lt;br /&gt;
&lt;br /&gt;
1: User input for how much RAM can be used.&lt;br /&gt;
&lt;br /&gt;
2: Consider putting the optional boundary constraints raster into RAM (dependent on available RAM).&lt;br /&gt;
&lt;br /&gt;
2: Use &amp;quot;zero&amp;quot; for segment ID's of Null cells, discard the NULL flag.  (Need to check speed impact with Seg ID in SEG storage.)&lt;br /&gt;
&lt;br /&gt;
3: Check input map type(s), currently storing in DCELL sized SEG file, could reduce this dynamically depending on input map time. (Could only reduce to FCELL, since will be storing mean we can't use CELL.  Might not be worth the added code complexity.)&lt;br /&gt;
&lt;br /&gt;
== Polish ==&lt;br /&gt;
&lt;br /&gt;
1: Add error traps.  (Certainly for memory allocation, Minimum number of non-NULL cells in the input bands?anything else?)&lt;br /&gt;
&lt;br /&gt;
2: Make the output segment ID's sequential (currently they have what ID the &amp;quot;first&amp;quot; pixel in the segment had).&lt;br /&gt;
&lt;br /&gt;
2: There are many small TODO scattered in the code. Resolve some easy questions to clean up the code.&lt;br /&gt;
&lt;br /&gt;
2: Change G_percentage: estimate total number of passes expected from histogram and threshold.  (If this isn't reliabe, maybe change to show 1% for each pass, i.e. % complete out of first 100 passes, then % complete out of next 100 passes, etc.)&lt;br /&gt;
&lt;br /&gt;
3: GUI (to combine i.segment with the stats module)&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
How to choose parameters, what their impact is.&lt;br /&gt;
&lt;br /&gt;
Typical workflow:&lt;br /&gt;
&lt;br /&gt;
* i.group&lt;br /&gt;
* i.segment&lt;br /&gt;
* r.to.vect&lt;br /&gt;
* i.segment.metrics and/or i.maxlik and/or r.fuzzy&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15989</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15989"/>
		<updated>2012-06-20T16:02:54Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Project Plan */ - added links to weekly reports&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work [http://lists.osgeo.org/pipermail/soc/2012-May/001747.html Report 1]&lt;br /&gt;
* Week 2-4: Implement the main algorithm [http://lists.osgeo.org/pipermail/soc/2012-June/001779.html Report 2] [http://lists.osgeo.org/pipermail/soc/2012-June/001804.html Report 3] [http://lists.osgeo.org/pipermail/soc/2012-June/001826.html Report 4]&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15988</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15988"/>
		<updated>2012-06-20T15:45:19Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */ - updated based on email discussions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, &amp;lt;del&amp;gt;or even image subgroup&amp;lt;/del&amp;gt;, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module) (Update: subgroups are not often used, there use will not be implemented unless someone asks.)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
*** Default action will be to normalize/scale all input rasters to a 0-1 range.  The allows bands (0-255), NDVI, and other numbers to be compared on an equal basis in the distance formula without any preprocessing steps.  Since it gives equal weights to all rasters in the input group, a flag will give the user the option to skip this normalization step in case they want to use the actual values.&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Similarity measurement&lt;br /&gt;
** The squared euclidean distance will be the default similarity measurement.  If time allows, Manhattan distance will be added as an option.  (Using the square will give same results, we will also square the similarity threshold so the user doesn't need to worry about this detail.&lt;br /&gt;
** For the default scaling of the input, the similarity threshold will be 0 to 1.  This should be a good intuitive range for the user, 0 being the entire image is one segment and 1 being no segments can be formed.  (Internally, this number must be multiplied by the number of rasters in the image group, but again the user doesn't need to worry about the details.)  If the user selects the option to skip the normalization function, they will need to be careful how to select this parameter.&lt;br /&gt;
* Output&lt;br /&gt;
** first (segmentation) module: raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** second (stats) module: one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.  Update: Using 4 neighbors as default, with optional flag to select 8 neighbors.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?  Update: current plan is to ignore all NULL values in the calculations.&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15987</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15987"/>
		<updated>2012-06-20T15:19:54Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Abstract */  - splitting segmentation and stats into two modules.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
Update: This process will be split into two modules, the first will output a raster map with segments, the second will compute statistics for the segments.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15875</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15875"/>
		<updated>2012-06-08T13:42:10Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Region Growing Algorithm */  (fixed typo in formula)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
ML: I would say leave decisions on color space (which is just one portion of feature space) to the user: one can group any kind raster maps with i.group and submit that to segmentation, and so the user can decide whether to use an image represented by different bands in a specific color space, plus any kind of other bands, indices, etc.&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; 0, t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15786</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15786"/>
		<updated>2012-05-29T15:18:31Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
&lt;br /&gt;
Number of modules:  Should the user run one module to create the segments (raster output), then if they are interested, run r.to.vect and run a second module (vector input/output) if they want to get the statistics.  (GUI glue to put them in one screen would be a low priority task for time remaining at the end of the summer.)  (I wonder if the stats module should take vector or raster as the input, it will also need the original raster.)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Probability of belonging to the segment&amp;quot;: For region growing - should this be the similarity measure when it was merged?  Or similarity measure of the pixel compared to the average?&lt;br /&gt;
/*ML: Not sure, but I would think that similarity between pixel and average of region it belongs to might be a good choice. Am not a specialist in statistics, but maybe it is possible to translate this into some form of probability of really &amp;quot;belonging&amp;quot; to that region (cf i.maxlik)*/&lt;br /&gt;
So this would be a comparison of the pixel to the final segment.  Does anyone have a standard measurement that should be used?&lt;br /&gt;
&lt;br /&gt;
4 vs. 8 neighbors:  Should this be a user input option?  It seems 4 neighbors (no diagonals) is the normal definition for segmentation, but not for other GRASS modules.&lt;br /&gt;
&lt;br /&gt;
Null cells: Is it possible for some pixels inside the image to have null values?  If yes, should they just be excluded from the calculation, or merged into the nearest segment?&lt;br /&gt;
&lt;br /&gt;
Are there any examples of using linear features to constraint segment growth, or will it usually be polygons?&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15699</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15699"/>
		<updated>2012-05-25T15:49:25Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: added code repository in header info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Repository: || AddOns, browse at: [https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.segment i.segment]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15652</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15652"/>
		<updated>2012-05-24T19:59:09Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
[http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471377392.html?0471377392=] Pitas, I:  Digital Image Processing Algorithms and Applications, 2000 (Textbook, including 1 chapter on segmentation methods.)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15651</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15651"/>
		<updated>2012-05-24T19:56:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Segmentation Methods */  - added section on region growing variations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
=== Region Growing Variations ===&lt;br /&gt;
&lt;br /&gt;
Even within the region growing label, there are a number of approaches.  Here are two described in [5].&lt;br /&gt;
&lt;br /&gt;
1.  Growing&lt;br /&gt;
&lt;br /&gt;
Seeds (as a subset of the pixels) are selected (using image histogram, previous knowledge, or other methods).  Region growing is done by adding adjacent pixels.  No merging of segments is done, only unassigned pixels can be assigned to adjacent regions.&lt;br /&gt;
&lt;br /&gt;
2.  Growing and Merging&lt;br /&gt;
&lt;br /&gt;
Use all pixels as seeds, no need to have user figure out a reasonable starting seed selection.  Now adjacent segments can be merged.&lt;br /&gt;
&lt;br /&gt;
Is there ever a case where someone may want to start with seeds, but still allow segment merging?  Or does that fall into the realm of classification to be done in the next step?&lt;br /&gt;
&lt;br /&gt;
At this point, it seems both variations should be implemented.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15650</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15650"/>
		<updated>2012-05-24T19:32:02Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */ -updated input - idea of feature space instead of color space&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
*** This input group will define the feature space which can include spectral and other continuous (elevation, PCA layers, slope aspect...) and possibly (probably not initially) even discrete data (soil type, land cover...)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15649</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15649"/>
		<updated>2012-05-24T17:20:18Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: added header for Workflow&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= Workflow =&lt;br /&gt;
&lt;br /&gt;
Todo: Some typical workflow examples, type of data, GRASS modules used before and after the image segmentation.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15648</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15648"/>
		<updated>2012-05-24T17:19:15Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;br /&gt;
&lt;br /&gt;
eCognition Reference Manual&lt;br /&gt;
&lt;br /&gt;
Kurtz et. al: Hierarchical Segmentation of Multiresolution Remote Sensing Images, 2011&lt;br /&gt;
&lt;br /&gt;
Comaniciu, Dorin: Mean Shift: A Robust Approach Toward Feature Space Analysis, 2002&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15644</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15644"/>
		<updated>2012-05-24T16:09:50Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Region Growing Algorithm */ adjusted terminology&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Similarity Threshold T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area  (Is this wanted or needed ???)&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15643</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15643"/>
		<updated>2012-05-24T16:01:43Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Lower priority */ some specifications to be added later&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
&lt;br /&gt;
Add shape characteristics (smoothness, compactness) to the similarity measurement.  Similar to eCognition &amp;quot;Multiresolution Segmentation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15642</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15642"/>
		<updated>2012-05-24T15:59:22Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Segmentation Considerations */  Added second approach for top down multiscalar segmentation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation.  {Or by using a vector map of the first segmentation as a boundary constraint in the second segmentation.} The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15641</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15641"/>
		<updated>2012-05-24T15:56:41Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Segmentation Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithms are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15640</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15640"/>
		<updated>2012-05-24T15:55:11Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Lower priority ===&lt;br /&gt;
It may be useful to do some calculations for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15583</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15583"/>
		<updated>2012-05-22T20:45:40Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
** Be able to process large images while being considerate of system memory&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15582</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15582"/>
		<updated>2012-05-22T20:42:26Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Segmentation Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing + &lt;br /&gt;
* Combined boundary/region (is this a correct category for these two?)&lt;br /&gt;
** mean-shift&lt;br /&gt;
** watershed&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
I don't recall the source, but I read in one place that mean-shift could be difficult to apply to very large images, and elsewhere it was mentioned watershed sees more use in greyscale images.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithms with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15581</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15581"/>
		<updated>2012-05-22T20:38:22Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
*** centroids/points to be used as initial seeds&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15579</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15579"/>
		<updated>2012-05-22T18:27:55Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Program Steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Region Growing Algorithm =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Region Growing, bottom up processing.  Main improvement compared to simple algorithm is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk's neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15578</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15578"/>
		<updated>2012-05-22T18:23:10Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Test Images */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered? [4]&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.  Main improvement is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15577</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15577"/>
		<updated>2012-05-22T18:22:52Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.  Main improvement is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;br /&gt;
&lt;br /&gt;
[http://www.isprs.org/proceedings/XXXV/congress/comm4/papers/506.pdf] G. Meinel, M. Neubert: A Comparison of Segmentation Programs for High Resolution Remote Sensing Data, 20?? (Includes timing to complete segmentation)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15576</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15576"/>
		<updated>2012-05-22T18:14:50Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
** What segmentation algorithm to use&lt;br /&gt;
** Parameters for that algorithm&lt;br /&gt;
** Distance function to use.  (RGB, HSI, L*u*v*, L*a*b*)  Should this be input??&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** combination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.  Main improvement is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15552</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15552"/>
		<updated>2012-05-22T03:40:35Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Program Steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** comination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.  Main improvement is to slowly lower the similarity function, so only best matches are made first.  This prevents the &amp;quot;first&amp;quot; segment from taking over any unclear areas between it and the next clear segment.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later addition can be alternate seeding methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower.  SPRING used:  &amp;lt;math&amp;gt;T(t) = T(0) alpha^t   &amp;lt;/math&amp;gt;, where T(0) &amp;gt; ), t =0,1,2... and alpha &amp;lt;1&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. Loop for t&lt;br /&gt;
** initialize candidate regions, save mean value vector and neighboring regions  (Not sure why this needs to be calculated/saved ahead of time ??)&lt;br /&gt;
3. For each region i in candidate region set (first pass this equals the seeds):&lt;br /&gt;
** Compare Ri with neighbors  (Question: should neighbors include or exclude those regions that were already matched?&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D of all neighbors and and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. next t, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15551</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15551"/>
		<updated>2012-05-22T03:27:21Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** comination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later modifications - alternate seed methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. For each region i in candidate region set:&lt;br /&gt;
** Compare Ri with neighbors&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. Increment t and repeat step 2, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;br /&gt;
&lt;br /&gt;
[http://www.sciencedirect.com/science/article/pii/S0031320300001497] Cheng et. al.: Color image segmentation: advances and prospect, 2000  (survey of segmentation methods and color spaces)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15550</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15550"/>
		<updated>2012-05-22T03:22:19Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** comination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
=== Questions ===&lt;br /&gt;
Will the user want input for the color space (RGB, HSI, L*u*v*, L*a*b*)?  (I saw one paper [3] discussing pro/con of different systems, &amp;quot;best&amp;quot; answer is application dependent.)&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later modifications - alternate seed methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. For each region i in candidate region set:&lt;br /&gt;
** Compare Ri with neighbors&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. Increment t and repeat step 2, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15549</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15549"/>
		<updated>2012-05-22T03:09:21Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** comination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later modifications - alternate seed methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. For each region i in candidate region set:&lt;br /&gt;
** Compare Ri with neighbors&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. Increment t and repeat step 2, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[http://www.armurs.ulb.ac.be/images/8/86/PERS_Carleer_05.pdf] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations, 2005 (Evaluates 2 boundary and 2 region based algorithms.)&lt;br /&gt;
&lt;br /&gt;
[http://marte.dpi.inpe.br/col/sid.inpe.br/deise/1999/02.05.09.30/doc/T205.pdf] Bins, et al: Satellite Imagery Segmentation: A Region Growing Approach, 1996  (Describes approach taken in SPRING software.)&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15547</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15547"/>
		<updated>2012-05-21T16:41:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** comination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= Program Steps =&lt;br /&gt;
&lt;br /&gt;
Here is (a start!) for the processing steps, based on SPRING [2]&lt;br /&gt;
&lt;br /&gt;
Image Growing, bottom up processing.&lt;br /&gt;
&lt;br /&gt;
1. Input:&lt;br /&gt;
** Seeds:  all pixels  (Later modifications - alternate seed methods)&lt;br /&gt;
** Comparison function T(t)... as t increases, threshold for similarity is lower&lt;br /&gt;
** Size of smallest allowed area&lt;br /&gt;
2. For each region i in candidate region set:&lt;br /&gt;
** Compare Ri with neighbors&lt;br /&gt;
** If it exists, Rk is best neighbor if smallest D and D &amp;lt; T.&lt;br /&gt;
** Check Rk neighbors.&lt;br /&gt;
** Merge IF Ri is Rk's best neighbor&lt;br /&gt;
** remove from candidate region set.  (give all &amp;quot;small&amp;quot; regions a chance to merge with best neighbor before growing larger regions)&lt;br /&gt;
** update segment values&lt;br /&gt;
** next i&lt;br /&gt;
3. Increment t and repeat step 2, with all segments returned to candidate region set, until no regions can be merged&lt;br /&gt;
&lt;br /&gt;
4. Force a merge of regions that are too small&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[1] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations&lt;br /&gt;
&lt;br /&gt;
[2] Bins, et al: Satellite Imagery Segmentation: a region growing approach&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15546</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15546"/>
		<updated>2012-05-21T14:08:03Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: /* Test Images */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
In order to respond to the issue of over/under-segmentation, a multiscalar approach would be interesting. This would mean either a top-down approach with a first coarse segmentation (under-segmentation) and the finer segmentation in selected segments, or a bottom-up approach with first a very fine-grained segmentation (over-segmentation) and the regrouping of segments to form higher levels. The first approach can be solved by doing a first segmentation, using certain segments as masks and then relaunching a second segmentation. The second approach requires an algorithm to decide which segments should be combined in a larger higher-level segments. A simple nearest neighbor or kmeans approach based on spectral mean can be used here. In terms of implementation in GRASS, this would probably call for several modules, one for the segmentation, and another for grouping of segments. The latter could be an all-purpose clustering module (and can also be emulated by simple data analysis in the attribute table + {{cmd|v.dissolve}}).&lt;br /&gt;
&lt;br /&gt;
It can sometimes be interesting to do a first segmentation on one band (e.g. panchromatic with higher resolution) and then regroup segments based on multispectral data (possibly weighting bands).&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* General considerations&lt;br /&gt;
&lt;br /&gt;
** The general principle in GRASS is KISS, with each module doing one thing. It is to be seen if the result of this project is one single module or rather more than one module each specialised in one task in a segmentation workflow.&lt;br /&gt;
** As soon as code is to be (potentially) used in several modules, the use of a library should be envisaged.&lt;br /&gt;
* Input&lt;br /&gt;
** in the GRASS logic, input should be an image group, or even image subgroup, which can contain any number of raster maps, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** lines (be it linear features or boundary lines of polygons) should be used as constraints meaning that no segment boundary should cross such a line&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** one vector map of segments per hierarchy level with a series of attributes (not all of these attributes should probably be calculated directly be the segmentation module)&lt;br /&gt;
*** spectral attributes: &lt;br /&gt;
**** per spectral band: mean, min, max, skewness&lt;br /&gt;
**** comination of bands: brightness, indices (i.e. results of multi-band calculations)&lt;br /&gt;
*** textural attributes: stdev (per-band and/or multi-band), mean difference to neighbor, Haralick texture features cf {{cmd|r.texture}}&lt;br /&gt;
*** geometric/morphological attributes: area, perimeter, length/width measures, see also {{cmd|r.li}}&lt;br /&gt;
*** context attributes: mean difference to all other regions in the same upper hierarchical level, relative localisation within upper hierarchical level, absolute localisation, number of objects in lower level&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  The North Carolina GRASS sample location will be used for documentation and manuals.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should check segmentation results on images from a few different resolutions and different numbers of bands against what is obtained in other software.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[1] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15519</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15519"/>
		<updated>2012-05-15T20:06:31Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{GSoC}}&lt;br /&gt;
''(See also other [[GRASS_SoC_Ideas_2012#Accepted_Ideas|GRASS GSoC 2012 projects]])''&lt;br /&gt;
&lt;br /&gt;
{| {{table}}&lt;br /&gt;
|Student Name: || Eric Momsen&lt;br /&gt;
|-&lt;br /&gt;
|Organization: || [http://www.osgeo.org OSGeo - Open Source Geospatial Foundation]&lt;br /&gt;
|-&lt;br /&gt;
| Mentor Name: ||     Mentor: Markus Metz (backup mentors: M Lennert, P Roudier)&lt;br /&gt;
|-&lt;br /&gt;
| Title: || '''Image Segmentation'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS GIS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented. The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS GIS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The {{cmd|i.smap}} module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at [[Image classification]]. Furthermore, the module {{AddonCmd|r.seg}} in GRASS-addons uses internally the Mumford-Shah variational model for image segmentation.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Methods ==&lt;br /&gt;
&lt;br /&gt;
* Boundary Based&lt;br /&gt;
** optimal edge detector +&lt;br /&gt;
** watershed +&lt;br /&gt;
* Region Based&lt;br /&gt;
** multilevel thresholding technique +&lt;br /&gt;
** region growing+ &lt;br /&gt;
** mean-shift (does it fall under region based grouping?)&lt;br /&gt;
&lt;br /&gt;
Carleer et.al. [1] reviewed 4 methods (marked with + above).  Boundary based methods are sensitive to noise and texture, and usually depend on good pre-processing.  (Does GRASS already have this pre-processing/filtering?)  Good results with urban zones, high contrast.  Both region based methods had difficulty with transition zones.  Region growing was less sensitive to texture (good for high resolution (1m) images).  Multi-level techniques are the only way to get all objects without over-segmentation.&lt;br /&gt;
&lt;br /&gt;
As additional algorithm's are added to the module, attention should be given to diversify so algorithm's with different strengths are implemented first.&lt;br /&gt;
&lt;br /&gt;
== Segmentation Considerations ==&lt;br /&gt;
&lt;br /&gt;
All(?) methods have some input parameter(s) that can be set.  These parameters influence if the algorithm will over-segment (one expected region is divided into 2 or more segments) or under-segment (putting two expected regions into one segment).  If the segments are used for later classification, over-segmentation should usually get preference to under-segmentation.  With extensive over-segmentation, some of the advantages provided by segmentation can be lost, but at least the classification can combine the segments into the expected region.  Under-segmentation is more critical, as the classification step will not divide the segment to recover the different regions.  (Based on a summary of a number of papers from [1])&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
* Input&lt;br /&gt;
** any raster map, but generally satellite or areal images that are pre-processed and ready for analysis (i.e. no pre-processing in the module)&lt;br /&gt;
** optionally vector maps of existing features&lt;br /&gt;
*** linear feature would indicate compulsory limits of segments&lt;br /&gt;
*** polygonal features would indicate existing known segments&lt;br /&gt;
* Algorithm of segmentation&lt;br /&gt;
** in GSoC implementation of only one algorithm&lt;br /&gt;
** code should be structured to allow easy implementation of additional algorithms&lt;br /&gt;
** multi-scalar segmentation can significantly improve results and should thus be implemented if possible (see i.smap code for example)&lt;br /&gt;
* Output&lt;br /&gt;
** raster map of segments (i.e. each pixel value represents id of segment the pixel belongs to)&lt;br /&gt;
** vector map of segments with a series of attributes&lt;br /&gt;
*** spectral attributes: XXX&lt;br /&gt;
*** textural attributes: XXX&lt;br /&gt;
*** morphological attributes: XXX&lt;br /&gt;
** depending on segmentation algorithm: raster map indicating for each pixel the probability of belonging to the segment it was put into, i.e. some measure of reliability of results&lt;br /&gt;
&lt;br /&gt;
= Test Images =&lt;br /&gt;
&lt;br /&gt;
The results of the implemented algorithm should be compared against the results of a similar algorithm implement in other software.  Sample images publicly available can also be used for the documentation.&lt;br /&gt;
&lt;br /&gt;
Carleer [1] used images with 1m resolution from Ikonos, panchromatic band from 08 June 2000, Brussels area.&lt;br /&gt;
&lt;br /&gt;
Should test (and demo?) images from a few different resolutions and different numbers of bands.&lt;br /&gt;
&lt;br /&gt;
Is there a benchmark for processing speed that should be considered?&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: Contingency time for finishing the above, ensure a solid main program. &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to {{cmd|i.maxlik}} to ensure the segmentation output can be used as input for the existing classification functionality&lt;br /&gt;
* GUI&lt;br /&gt;
* Adding a second image segmentation algorithm&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
TODO: complete references with links.&lt;br /&gt;
&lt;br /&gt;
[1] Carleer, et al: Assessment of Very High Spatial Resolution Satellite Image Segmentations&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15442</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15442"/>
		<updated>2012-04-30T04:34:29Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented.  The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The i.smap module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at http://grass.osgeo.org/wiki/Image_classification&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Specifications=&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: GUI &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15441</id>
		<title>GRASS GSoC 2012 Image Segmentation</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_GSoC_2012_Image_Segmentation&amp;diff=15441"/>
		<updated>2012-04-30T04:31:16Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: Google Summer of Code (GSoC) 2012 background, plan and weekly reports for Image Segmentation project.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract=&lt;br /&gt;
&lt;br /&gt;
GRASS has many imagery related processing capabilities, but the field is rapidly developing and many techniques are not yet implemented.  The goal of this GSoC project is to implement the region growing image segmentation algorithm.&lt;br /&gt;
&lt;br /&gt;
Input: Raster map(s) to be segmented (plus optional vector map for a constraint)&lt;br /&gt;
&lt;br /&gt;
Output: To include segmented regions with statistics. This information can be directly used or taken as input to existing image classification modules.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Image classification techniques already implemented in GRASS include supervised and unsupervised classification. Classification of images based on pixels can often be very noisy. By first segmenting the image, later classification of 'objects' can be more effective. Noise is reduced, classification speed is increased, and most importantly the classification is performed on objects instead of pixels. The i.smap module does include a segmentation step (based on Gaussian mixture distribution), but there does not exist a module intended to segment the image and provide segment data for general use. A summary of the existing methods implemented in GRASS are at http://grass.osgeo.org/wiki/Image_classification&lt;br /&gt;
&lt;br /&gt;
=Main Goal=&lt;br /&gt;
&lt;br /&gt;
Implement an image segmentation method to extend the available options for image processing in GRASS. The region growing method has been selected as a robust general purpose method. An important contribution of the new method will be to include vector maps (for example road networks) as a constraint in growing the segments. Output from the module will include Spectral (mean/variance/range/ect) and Spatial (area/shape/location/etc) data for each region.&lt;br /&gt;
&lt;br /&gt;
=Feature Requests=&lt;br /&gt;
&lt;br /&gt;
=Project Plan=&lt;br /&gt;
&lt;br /&gt;
Preparation: Gather ideas from the community!  Feature requests, image segmentation literature, and any other ideas and suggestions.&lt;br /&gt;
&lt;br /&gt;
* May 21: Start coding, 8 weeks until Midterm Evaluation &lt;br /&gt;
* Week 1: Develop pseudocode to outline the work &lt;br /&gt;
* Week 2-4: Implement the main algorithm&lt;br /&gt;
* Week 5: Add vector maps as a constraint to the segmentation&lt;br /&gt;
* Week 6: Validation &lt;br /&gt;
* Week 7: Debugging &lt;br /&gt;
* Week 8: GUI &lt;br /&gt;
* July 9: Midterm Evaluation: Evaluate the existing program, determine the plan for the remaining 3-4 weeks. Options include:&lt;br /&gt;
* Improving the main algorithm&lt;br /&gt;
* Adding control for what scale the segmentation is performed at&lt;br /&gt;
* Providing updates to i.maxlik to ensure the segmentation output can be used as input for the existing classification functionality&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_SoC_Ideas_2012&amp;diff=15440</id>
		<title>GRASS SoC Ideas 2012</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_SoC_Ideas_2012&amp;diff=15440"/>
		<updated>2012-04-30T04:17:21Z</updated>

		<summary type="html">&lt;p&gt;⚠️Emomsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:grasslogo_vector_small.png|link=http://grass.osgeo.org]]&amp;lt;font size=&amp;quot;+3&amp;quot;&amp;gt; @ &amp;lt;/font&amp;gt; [[Image:Gsoc-2012-logo-color.png|250px|link=http://wiki.osgeo.org/wiki/Google_Summer_of_Code_2012]] &amp;lt;font size=&amp;quot;+3&amp;quot;&amp;gt; @ &amp;lt;/font&amp;gt; [[Image:OSGeo 220pix.png|link=http://www.osgeo.org]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* See also previous Google Summer of Code [[GRASS SoC Ideas 2011|ideas from 2011]].&lt;br /&gt;
&lt;br /&gt;
* Visit the [http://wiki.osgeo.org/wiki/Google_Summer_of_Code_2012 main OSGeo Google Summer of Code 2012 @ OSGeo wiki page].&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
== About ==&lt;br /&gt;
&lt;br /&gt;
This is the GRASS page for [http://wiki.osgeo.org/index.php/Google_Summer_of_Code Google Summer of Code 2012]. Here we will list project ideas and and other information related to the GRASS GSoC projects.&lt;br /&gt;
&lt;br /&gt;
* [http://code.google.com/soc/ Official Google Summer of Code 2012 homepage]&lt;br /&gt;
* [http://wiki.osgeo.org/wiki/Google_Summer_of_Code_2012 OSGeo SoC 2012 homepage]&lt;br /&gt;
&lt;br /&gt;
Promotion:&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
 * OSGeo Flyer at &amp;lt;s&amp;gt;http://svn.osgeo.org/osgeo/marketing/flyer/google_summer_of_code/OSGeo_GSoC_2012.pdf &amp;lt;/s&amp;gt;(todo)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
* Videos at      http://code.google.com/p/google-summer-of-code/wiki/Videos&lt;br /&gt;
* More Flyers at http://code.google.com/p/google-summer-of-code/wiki/GsocFlyers&lt;br /&gt;
&lt;br /&gt;
== Timeline ==&lt;br /&gt;
&lt;br /&gt;
* '''[http://www.google-melange.com/gsoc/document/show/gsoc_program/google/gsoc2012/faqs#timeline The official timeline]'''&lt;br /&gt;
&lt;br /&gt;
== Required Steps ==&lt;br /&gt;
&lt;br /&gt;
* '''List ideas'''&lt;br /&gt;
&lt;br /&gt;
* Assign Mentors to Ideas&lt;br /&gt;
&lt;br /&gt;
* Notify OSGeo&lt;br /&gt;
&lt;br /&gt;
* Mentors evaluate student applications&lt;br /&gt;
&lt;br /&gt;
* Accepted students announced&lt;br /&gt;
&lt;br /&gt;
* Students subscribe to the [http://lists.osgeo.org/mailman/listinfo/grass-dev grass-dev mailing list] and introduce themselves&lt;br /&gt;
&lt;br /&gt;
* Mentor will create directory structure in the [http://trac.osgeo.org/grass/browser/grass-addons GRASS add-ons SVN] for projects and setup access for students&lt;br /&gt;
** Students must read and post agreement to [http://grass.osgeo.org/programming7/rfc2_psc.html RFC2] to the [http://lists.osgeo.org/mailman/listinfo/grass-psc grass-psc mailing list] to gain SVN access&lt;br /&gt;
** Create a Wiki page for each accepted project, to be used as a progress reporting tool&lt;br /&gt;
&lt;br /&gt;
* Coding begins...&lt;br /&gt;
&lt;br /&gt;
* Students and mentors: Complete the Mid-term survey&lt;br /&gt;
&lt;br /&gt;
* Final commit and packaging for Google&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
&lt;br /&gt;
* Also review ideas from [[GRASS SoC Ideas 2007#Ideas|2007]], [[GRASS SoC Ideas 2008#Ideas|2008]], [[GRASS SoC Ideas 2009#Ideas|2009]], [[GRASS SoC Ideas 2010#Ideas|2010]], and [[GRASS SoC Ideas 2011#Ideas|2011]]  which are still open.&lt;br /&gt;
&lt;br /&gt;
* Project ideas of '''your own''' are also most welcome and often the best.&lt;br /&gt;
&lt;br /&gt;
=== [[wxGUI]] ===&lt;br /&gt;
&lt;br /&gt;
# Develop GUI support in wxPython for visualy analyzing series of raster map layers. The module should provide users with capabilities to browse and animate raster (and potentially also vector) data series in a 2D display and save outputs to animated GIF, MOV, or MPEG files. A related module that displays the series as small images and support re-ordering, deleting and adding raster maps (frames) to the series would also be helpful. To compare visually two images a slider functionality could be added to the 2D display, for example, to compare before and after images, or two consequent images in series. The series of data layers can be handled as multiple standard raster or vector layers or using  the new time series support. See existing modules {{cmd|xganim}}, {{cmd|r.out.mpeg}}, [[NVIZ]]'s animation tools, and the [[Movies]] creation wiki page. There is also a related capability in the TclTk GUI. (co-mentor Helena Mitasova).&lt;br /&gt;
# Develop an interactive vector geometry selection and export tool for [[wxGUI]] as described in the trac ticket [http://trac.osgeo.org/grass/ticket/1471 #1471]&lt;br /&gt;
# Offer also (optional) &amp;quot;conventional&amp;quot; '''GUI layout''': For some users, the current approach of separate windows (SDI) leads to a '''windows flooding'''. This is a common complaint especially from newbies. Especially on large monitors or dual screen systems catching the [[wxGUI]] windows can be tedious when they appear on separate monitors (depends on windows manager, the much used KDE scatters typically the wxGUI windows all over the screen real estate). Almost each task generates a new wxGUI window which is freely floating around on the screen:  [http://grass.osgeo.org/grass63/screenshots/images/wxgrass_digit-03.png example 1] and [http://grass.osgeo.org/grass63/screenshots/images/wxgrass_digit-01.png example 2]. On a dual-screen this may sum up to 50cm of distance! The idea is to capture all those windows in one frame. For details, see [[wxGUI#Layout| wxGUI layout]].&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;lt;gallery widths=400 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_current.png|Current wxGUI layout with detached window components&lt;br /&gt;
Image:Wxgui_proposal.png|Proposal for wxGUI layout modification (Recomposition of existing toolbars, mapview and menus)&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
# ''Your idea here''&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' [[User:Landa|Martin Landa]], [[User:MarisN|Maris Nartiss]], [[User:Mmetz|Markus Metz]], (''your name here'')&lt;br /&gt;
&lt;br /&gt;
=== Raster  ===&lt;br /&gt;
&lt;br /&gt;
#Add '''[[OpenMP]] parallelization''' where appropriate, for example {{cmd|r.cost}}, {{cmd|r.surf.contour}}, {{cmd|r.watershed}}. It is important to understand which modules are processor bound, and concentrate on them. i.e. do not needlessly complicate the code of non-long running processor bound modules. A good working knowledge of ANSI C and {{wikipedia|OpenMP}} is required. ({{wikipedia|OpenCL}} and {{wikipedia|pthreads}} are fine too!) &lt;br /&gt;
#Create a new GRASS module to find the {{wikipedia|topographic_prominence}} of peaks from a raster elevation map within the region. (probably this would only make up 1/4 to 1/2 of a multi-part GSoC project) &lt;br /&gt;
# ''Your suggestion here!''&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' Hamish (co-mentor parallelization and prominence projects), Wolf Bergenheim(''your name here'')&lt;br /&gt;
&lt;br /&gt;
=== Vector ===&lt;br /&gt;
&lt;br /&gt;
# Add '''[[OpenMP]] parallelization''' where appropriate, for example, {{cmd|v.surf.rst}} and {{cmd|v.vol.rst}} ''(co-mentor Helena Mitasova)''. (OpenCL and pthreads are fine too!) See above idea in the [[GRASS SoC Ideas 2012#Raster|Raster section]].&lt;br /&gt;
# Better '''support for wrap-around at 180 longitude''': Currently the raster engine is pretty good at wrapping data over 180 longitude. The vector data isn't, but it should be. This is a great task if by the end of the summer you'd like to be familiar with the implementation method of an entire vector stack of a fully featured modern GIS.&lt;br /&gt;
# Add '''break lines support to interpolation modules''' ({{cmd|v.surf.rst}}, {{cmd|v.surf.idw}}, {{cmd|v.surf.bspline}}). Current implementations provide no support to specify locations of cliffs or faults* thus leading to improper results within non-continous datasets. See [http://www.spatialanalysisonline.com/output/html/Breaklinesandnaturalboundaries.html Geospatial Analysis - a comprehensive guide. 3rd edition] for description. [*] well, some support exists, see {{AddonCmd|v.surf.icw}}.&lt;br /&gt;
# Speed up [[wxGUI]] handling and 2D display of large point clouds (several million points). This is likely to include additional &amp;quot;Level-1 Vector&amp;quot; support in the backend modules (for which a working knowledge of ANSI C is req'd).&lt;br /&gt;
# ''Your idea here'' ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' [[User:Landa|Martin Landa]], [[User:Mmetz|Markus Metz]], Hamish (co-mentor for parallelization), Wolf Bergenheim, (''your name here'')&lt;br /&gt;
&lt;br /&gt;
=== Imagery ===&lt;br /&gt;
&lt;br /&gt;
# GRASS's imagery modules (for satellite, scanned maps, and orthophotos) act as enhanced raster modules. In GRASS 5 and 6 they were mostly implemented using interactive X-monitors which are not available in MS Windows and so are removed in the new cross-platform code of GRASS 7.&lt;br /&gt;
#* We need someone willing to '''port the old modules to work with GRASS 7''', including writing new '''wxPython GUI frontends''' to a number of existing tools and updating the imagery libraries to current raster library standards.&lt;br /&gt;
#* In addition, there are a number of '''improved/automated georectification tools''' which have not been merged into GRASS 5/6 which it would be nice to have updated and merged into the main code.&lt;br /&gt;
# Implement '''[[OpenMP]] (multithreading)''' as much as possible (where appropriate; OpenCL and pthreads are fine too)&lt;br /&gt;
# In addition to the porting of the georectification tools mentioned above, it would be interesting to implement an orthorectification tool for satellite imagery. Currently, GRASS only has {{cmd|i.ortho.photo}} for aerial photographs.&lt;br /&gt;
# Implement image segmentation algorithms and tools&lt;br /&gt;
# Implement region-based classification&lt;br /&gt;
# Implement hierarchical classification tools (e.g. being able to create a large class &amp;quot;forest&amp;quot;, with subclasses of different types of forests)&lt;br /&gt;
# ''Your idea here''&lt;br /&gt;
&lt;br /&gt;
See the [[Image_processing#Ideas_collection_for_improving_GRASS.27_Image_processing_capabilities|ideas for imagery improvement]] and [http://trac.osgeo.org/grass/wiki/Grass7/ImageryLib GRASS 7 ideas] wiki pages for more details.&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' Hamish (co-mentor for parallelization), Markus Metz (orthorectification), (''your name here'')&lt;br /&gt;
&lt;br /&gt;
=== Cartography and display ===&lt;br /&gt;
&lt;br /&gt;
# Add SVG (and perhaps EPS) support to the display library, for use via {{cmd|d.graph}} and/or {{cmd|d.vect}}, and add SVG support to {{cmd|ps.map}} via a SVG to EPS converter tool (probably by adapting an existing GPL-compatible library). Code to be written in ANSI C. Step 1 is adding a Bézier curve rendering library function.&lt;br /&gt;
# Integrate Quantum/GRASS SVG output plugin with Inkscape. Python can serve as a common glue between these tools. The project would facilitate easy cartographic workflow while utilizing the advanced design functionality of Inkscape. This would be a two way bridge:&lt;br /&gt;
## QGIS/GRASS plugins to invoke an Inkscape process and send a data set.&lt;br /&gt;
## Inkscape plugin to query various OSGeo projects and display various data sets as layers.&lt;br /&gt;
# ''Your idea here ...''&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' Hamish (as a co-mentor)&lt;br /&gt;
&lt;br /&gt;
=== 3D visualization ===&lt;br /&gt;
&lt;br /&gt;
# Optimize OGSF (and NVIZ/wxNVIZ) to '''display large 3D point clouds with uninterupted tought speed'''. OGSF + (wx)NVIZ should be able to rotate point cloud (i.e. LiDAR dataset) with 4 millions of points on medium hardware (i.e. 2GHz CPU with 2Gb RAM and GPU with hardware transform and lighting support and dedicated video RAM) with response time not greater than 1.0 second.&lt;br /&gt;
# Design and implement '''text displaying and styling in OGSF library''' and it's front-ends (NVIZ, [[wxNVIZ]]). Solution should be user configurable (fonts, colors, effects etc.) and multilanguage friendly.&lt;br /&gt;
# Design and implement user-provided '''symbol support in OGSF library''' and it's front-ends (NVIZ, [[wxNVIZ]]). Solution should support GRASS symbols, SVG, and/or simple EPS symbols.&lt;br /&gt;
&amp;lt;!-- # Add/fix missing features to [[wxNVIZ]] (lighting, robust handling of z-exageration and viewing position including latlong data, cutting planes, multiattribute 3D points, decorations: scale, north, legend, text, isosurfaces and slicing) --&amp;gt;&lt;br /&gt;
# Drape multiple color maps over topography (equivalent to running r.patch or r.composite and draping the result; second raster is currently supported as transparency).&lt;br /&gt;
# Improve handling of z-exageration so that z-exag=1  is a realistic representation of landscape in terms of vertical scaling. Other default settings could also be improved to support wider range of data and improve robustness.&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' [[User:Landa|Martin Landa]] (for 2), co-mentor for 1 and 5: Helena Mitasova, (''your name here'')&lt;br /&gt;
&lt;br /&gt;
=== Volume modeling ===&lt;br /&gt;
&lt;br /&gt;
# Develop '''r3.flow''' for computing 3D flow lines and 3D flow accumulation from 3D rasters&lt;br /&gt;
# Enhance volume interpolation module '''{{cmd|v.vol.rst}}''' for handling of data in space-time cube, including computation of gradients and hypercurvatures&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' co-mentor Helena Mitasova, [[User:Huhabla|Sören Gebbert]]&lt;br /&gt;
&lt;br /&gt;
=== Improved Python interface ===&lt;br /&gt;
&lt;br /&gt;
Design '''sophisticated Python scripting interface''' for GRASS based on [http://grass.osgeo.org/programming7/pythonlib.html GRASS Python Scripting Library]. This API should become more intuitive and more integrative&lt;br /&gt;
&lt;br /&gt;
GRASS GIS would gain even more attractiveness!&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' [[User:Huhabla|Sören Gebbert]]&lt;br /&gt;
&lt;br /&gt;
=== Other ===&lt;br /&gt;
&lt;br /&gt;
* See also the [https://trac.osgeo.org/grass/query?status=assigned&amp;amp;status=new&amp;amp;status=reopened&amp;amp;order=priority&amp;amp;col=id&amp;amp;col=summary&amp;amp;col=status&amp;amp;col=type&amp;amp;col=priority&amp;amp;col=milestone&amp;amp;col=component&amp;amp;type=enhancement GRASS wish list]&lt;br /&gt;
&lt;br /&gt;
# Implement selected modules (in C/C++) for geospatial analysis (kriging, etc.) based on [http://hpgl.aoizora.org/ HPGL] library (see also [http://hub.qgis.org/projects/quantum-gis/wiki/Python_Plugin_Ideas#Add-and-R-Free-geostatistic-toolbox-using-HPGL QGIS plugin wish]).&lt;br /&gt;
# Design and implement modern '''metadata management system''' for GRASS to support [http://www.opengeospatial.org/standards/cat OGC CSW] and INSPIRE discovery a view services&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
# Design '''GRASS toolboxes environment''', see [[GRASS repository layout proposal]] for detailed information. This would also include general clean up and organization of existing GRASS modules in trunk and add-ons.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
# ''Your idea here''&lt;br /&gt;
&lt;br /&gt;
'''Willing to Mentor:''' Wolf Bergenheim (Python API, metadata management), [[User:Landa|Martin Landa]] (for HPGL) (''your name here'')&lt;br /&gt;
&lt;br /&gt;
== Guidelines for Students ==&lt;br /&gt;
&lt;br /&gt;
How do you maximize your chances of getting picked? First read the [http://code.google.com/p/google-summer-of-code/wiki/AdviceforStudents Google SoC FAQ]. Then talk to us about your idea. Try emailing our [http://lists.osgeo.org/mailman/listinfo/grass-dev dev-mailing list], or come and talk to us in [[IRC]] (#grass). You can also reach the mentors directly by emailing:&lt;br /&gt;
* [http://lists.osgeo.org/mailman/listinfo/soc The OSGeo SoC mailing list]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
 * Anne (&amp;lt;tt&amp;gt; @ &amp;lt;/tt&amp;gt;)&lt;br /&gt;
 * Hamish (&amp;lt;tt&amp;gt;hamish_b at yahoo com&amp;lt;/tt&amp;gt;)&lt;br /&gt;
 * Wolf Bergenheim (&amp;lt;tt&amp;gt;wolf+grass at bergenheim.net&amp;lt;/tt&amp;gt;)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you are thinking about applying, do make a point of reading the &amp;quot;[http://google-opensource.blogspot.co.nz/2011/02/flip-bits-not-burgers-student-guide.html Flip bits not Burgers: The Student's Guide to the Summer of Code]&amp;quot; eBook&lt;br /&gt;
&lt;br /&gt;
=== Getting started with GRASS coding ===&lt;br /&gt;
&lt;br /&gt;
* The source code is maintained in a [http://trac.osgeo.org/grass/browser/grass/trunk SVN server] which is easy to browse&lt;br /&gt;
&lt;br /&gt;
* Please review the submitting files for our coding standards&lt;br /&gt;
** {{src|SUBMITTING|branch=trunk}} for C coding rules&lt;br /&gt;
** {{src|SUBMITTING_PYTHON|branch=trunk}} for Python coding rules&lt;br /&gt;
** {{src|SUBMITTING_DOCS|branch=trunk}} for Documentantion coding rules&lt;br /&gt;
&lt;br /&gt;
* There is lots of good info at the [http://trac.osgeo.org/grass/wiki GRASS Developer's wiki]&lt;br /&gt;
: See also the [[Development|development section]] of the GRASS user's wiki&lt;br /&gt;
&lt;br /&gt;
== Guidelines for Mentors ==&lt;br /&gt;
&lt;br /&gt;
* Un(?)official book: http://www.booki.cc/gsoc-mentoring/&lt;br /&gt;
* Some more hints on the [http://wiki.osgeo.org/wiki/Google_Summer_of_Code_2012_Administrative#Links OSGeo wiki]&lt;br /&gt;
&lt;br /&gt;
== Accepted Ideas ==&lt;br /&gt;
&lt;br /&gt;
# ''Python high level map interaction for GRASS GIS'' ([http://www.google-melange.com/gsoc/project/google/gsoc2012/zarch/11001 abstract])&lt;br /&gt;
#: Student: Pietro Zambelli&lt;br /&gt;
#: Mentor: Sören Gebbert&lt;br /&gt;
#: Backup mentors: Luca Delucchi, Martin Landa&lt;br /&gt;
#: Wiki page: [[GRASS SoC Ideas 2012/High level map interaction]]&lt;br /&gt;
# ''GRASS GIS WxGui front end for vector analysis modules'' ([http://www.google-melange.com/gsoc/project/google/gsoc2012/turek/38001 abstract])&lt;br /&gt;
#: Student: Stepan Turek&lt;br /&gt;
#: Mentor: Martin Landa&lt;br /&gt;
#: Backup mentor: Markus Metz&lt;br /&gt;
#: Wiki page: wiki/blog page maintained by the student (typically in this GRASS wiki, or the trac development wiki, with weekly progress reports)&lt;br /&gt;
# ''Image Segmentation in GRASS GIS'' ([http://www.google-melange.com/gsoc/project/google/gsoc2012/emomsen/20001 abstract])&lt;br /&gt;
#: Student: Eric Momsen&lt;br /&gt;
#: Mentor: Markus Metz&lt;br /&gt;
#: Backup mentors: Moritz Lennert, Pierre Roudier&lt;br /&gt;
#: Wiki page: [[GRASS GSoC Image Segmentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
# ''Project name''&lt;br /&gt;
#: Student: Someone else's name here&lt;br /&gt;
#: Mentor: Their mentor's name here&lt;br /&gt;
#: Backup mentor: Their backup mentor's name here&lt;br /&gt;
#: Wiki page: wiki page maintained by them (typically in this GRASS wiki, or the trac development wiki)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Community]]&lt;br /&gt;
[[Category:GSoC]]&lt;/div&gt;</summary>
		<author><name>⚠️Emomsen</name></author>
	</entry>
</feed>