Object-based classification (Tutorial)

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Training phase)
(Feature extraction)
 
(28 intermediate revisions by one user not shown)
Line 15: Line 15:
 
* In the search engine of Processing Toolbox, type {{typed|text=segmentation}} and double click '''Segmentation'''.
 
* In the search engine of Processing Toolbox, type {{typed|text=segmentation}} and double click '''Segmentation'''.
 
* Set {{button|text=Segmentation algorithm}} to '''meanshift'''
 
* Set {{button|text=Segmentation algorithm}} to '''meanshift'''
* Select the input image: '''Subset_S2A_MSIL2A_20170619T_MUL.tif ''' (data type uint 16bits).
+
* Select the input image: '''Subset_S2A_MSIL2A_20170619T_MUL.tif ''' (data type uint 16bit).
 
* The {{button|text=Range radius}} value can be set to {{typed|text=600}}. The optimal value depends on datatype dynamic range of the input image and requires experimental trials for the specific classifcation objectives.
 
* The {{button|text=Range radius}} value can be set to {{typed|text=600}}. The optimal value depends on datatype dynamic range of the input image and requires experimental trials for the specific classifcation objectives.
* Set {{button|text=Minimum Region size}} (in pixels) to {{typed|text=25}}.
+
* Set {{button|text=Minimum Region size}} (in pixels) to {{typed|text=16}}.
 
* {{button|text=Processing mode}} '''Vector'''
 
* {{button|text=Processing mode}} '''Vector'''
 
* Set the {{button|text=Mask image}} to blank (top of dro-down list).
 
* Set the {{button|text=Mask image}} to blank (top of dro-down list).
* The {{button|text=Minimum Segment size}} (in pixels) can be set to {{typed|text=25}} depending on  minimum mapping size.
+
* The {{button|text=Minimum Segment size}} (in pixels) can be set to {{typed|text=16}} depending on  minimum mapping size.
 
* Check {{button|text=8-neighborhood connectivity}} on.
 
* Check {{button|text=8-neighborhood connectivity}} on.
* Change {{button|text=Output pixel type}} to '''uint32'''.
+
* Name the {{button|text=Output vector file}} e.g. '''lucc_meanshift_seg.shp'''. (Filetype shapefile is here mandatory)
* Name the {{button|text=Output vector file}} e.g. '''lucc_meanshift_seg.shp'''.
+
* Define the {{button|text=Output labeled image}} as '''lucc_meanshift_seg.tif'''.
+
 
* Click {{button|text=Run}}.
 
* Click {{button|text=Run}}.
 +
If no-data are defined in the input image you will get the warning: "this application does not handle no-data". Ignore and load the shapefile with segments manually.
 +
 
[[File:qgis_otb_segmentation.png|400px]]
 
[[File:qgis_otb_segmentation.png|400px]]
 +
 
* Evaluate the segmentation results: Load the output vector file '''lucc_meanshift_seg.shp''' into QGIS on top of the image ''Subset_S2A_MSIL2A_20170619T_Mul.tif''
 
* Evaluate the segmentation results: Load the output vector file '''lucc_meanshift_seg.shp''' into QGIS on top of the image ''Subset_S2A_MSIL2A_20170619T_Mul.tif''
 
Mark the vector layer in the Qgis Layers window. {{mitem|text=Layer --> Properties --> Symbology  --> Simple Fill}}, {{mitem|text=Fill Style}}: ''No Brush'' and {{mitem|text=Stroke color}}:''white''.
 
Mark the vector layer in the Qgis Layers window. {{mitem|text=Layer --> Properties --> Symbology  --> Simple Fill}}, {{mitem|text=Fill Style}}: ''No Brush'' and {{mitem|text=Stroke color}}:''white''.
  
 
==Feature extraction==
 
==Feature extraction==
 +
In the search engine of Processing Toolbox, type {{typed|text=zonalstats}} and open '''ZonalStatistics''' under Image Manipulation of OTB.
 +
* Select the Input image: '''Subset_S2A_MSIL2A_20170619T_MUL.tif '''.
 +
* Background value to ignore: {{typed|text=65535}}
 +
* The input vector data is the result from Segmentation: '''lucc_meanshift_seg.shp'''.
 +
* File name for the output vector data: '''lucc_meanshift_seg_stats.shp'''.
 +
* Click {{button|text=Run}}.
 +
[[File:otb_zonalstats.png|400px]]
 +
 +
Alternative module:
 
* In the search engine of Processing Toolbox, type {{typed|text=zonal}} and double click '''Zonal Statistics'''.
 
* In the search engine of Processing Toolbox, type {{typed|text=zonal}} and double click '''Zonal Statistics'''.
 
* Select the Raster layer: '''Subset_S2A_MSIL2A_20170619T_MUL.tif '''.
 
* Select the Raster layer: '''Subset_S2A_MSIL2A_20170619T_MUL.tif '''.
 
* Set Raster band  {{button|text=Band 01}}.
 
* Set Raster band  {{button|text=Band 01}}.
* The vector layer containing zones is the result from Segmentation: '''lucc_meanshift_seg.tif'''.
+
* The vector layer containing zones is the result from Segmentation: '''lucc_meanshift_seg.shp'''.
 
* Change output column prefix to the original Sentinel-2 band name: {{typed|text=B1}}
 
* Change output column prefix to the original Sentinel-2 band name: {{typed|text=B1}}
 
* In the list Statistics to calculate just check two measures: '''Mean''' and '''Std. dev.'''.
 
* In the list Statistics to calculate just check two measures: '''Mean''' and '''Std. dev.'''.
Line 40: Line 50:
 
[[File:qgis_zonal_stats.png|400px]]
 
[[File:qgis_zonal_stats.png|400px]]
 
* Repeat the procedure for bands 02, 03, 04, 05, 06, 07, 08, 09, 10.
 
* Repeat the procedure for bands 02, 03, 04, 05, 06, 07, 08, 09, 10.
* Open the attribute table of vector layer '''lucc_meanshift_seg.tif''' containing now statistics for each zone or segment.
+
* Open the attribute table of vector layer '''lucc_meanshift_seg.shp''' containing now statistics for each zone or segment.
  
 
==Training phase==
 
==Training phase==
Line 47: Line 57:
 
* ''Output model filename'' is {{button|text=lucc_svm_obia.model}}
 
* ''Output model filename'' is {{button|text=lucc_svm_obia.model}}
 
* In the field ''Field names for training features'' copy and paste  
 
* In the field ''Field names for training features'' copy and paste  
 +
for OTB 7.0.0 Zonalstatistics module:
 +
<pre> "mean_0 mean_1 stdev_1 mean_2 mean_3 mean_4 mean_5 mean_6 stdev_6 mean_8 stdev_8 mean_9" </pre>
 +
or if you used the qgis zonal statistics module:
 
<pre> "B1mean B2mean B2stdev B3mean B4mean B5mean B6mean B7mean B7stdev B9mean B9stdev B10mean" </pre>
 
<pre> "B1mean B2mean B2stdev B3mean B4mean B5mean B6mean B7mean B7stdev B9mean B9stdev B10mean" </pre>
 
* The name of ''Field containing the class id for supervision" is {{button|text=C_ID}}.
 
* The name of ''Field containing the class id for supervision" is {{button|text=C_ID}}.
* Classifier to use for training: {{button|text=lisvm}}
+
* Classifier to use for training: {{button|text=libsvm}}
 
* SVM Kernel Type: {{button|text=linear}}
 
* SVM Kernel Type: {{button|text=linear}}
 
* SVM Model Type: {{button|text=csvc}}
 
* SVM Model Type: {{button|text=csvc}}
Line 58: Line 71:
  
 
==Classification phase==
 
==Classification phase==
 +
* In the search engine of Processing Toolbox, type {{typed|text=Vector}} and double click '''VectorClassifier'''.
 +
* Name of the input vector data is {{typed|text=lucc_segments.shp}}.
 +
* Name of the input model file is {{typed|text=lucc_svm_obia.model}}.
 +
* Output field containing the class is {{typed|text=C_ID}}
 +
* Copy and paste into the filed ''Field names to be calculated'' the '''same features''' as in the TrainVectorClassifier module:
 +
for OTB 7.0.0 Zonalstatistics module:
 +
<pre> "mean_0 mean_1 stdev_1 mean_2 mean_3 mean_4 mean_5 mean_6 stdev_6 mean_8 stdev_8 mean_9" </pre>
 +
or if you used the qgis zonal statistics module:
 +
<pre> "B1mean B2mean B2stdev B3mean B4mean B5mean B6mean B7mean B7stdev B9mean B9stdev B10mean" </pre>
 +
* Specify the Output vector file. {{button|text=Run}}
 
[[File:qgis_otb_vectorclassifier.png|400px]]
 
[[File:qgis_otb_vectorclassifier.png|400px]]
  
Line 63: Line 86:
 
==Segmentation==
 
==Segmentation==
 
* Type into the search box of the Windows taskbar: {{typed|text=mapla.bat}}. Click on mapla.bat to open  Monteverdi Application Launcher.
 
* Type into the search box of the Windows taskbar: {{typed|text=mapla.bat}}. Click on mapla.bat to open  Monteverdi Application Launcher.
* In the search engine of mapla, type {{typed|text=Meanshift}} and double click '''LargeScaleMeanshift'''.
+
* In the search engine of mapla, type {{typed|text=Segmentation}} and double click '''Segmentation'''.
 
* Select the input image: '''Subset_S2A_MSIL2A_20170619T_MUL.tif ''' (datatype uint 16bits).
 
* Select the input image: '''Subset_S2A_MSIL2A_20170619T_MUL.tif ''' (datatype uint 16bits).
 
* The {{button|text=Range radius}} value can be set to {{typed|text=600}}. The optimal value depends on datatype dynamic range of the input image and requires experimental trials for the specific classifcation objectives.
 
* The {{button|text=Range radius}} value can be set to {{typed|text=600}}. The optimal value depends on datatype dynamic range of the input image and requires experimental trials for the specific classifcation objectives.
* The value for {{button|text=Minimum Segment size}} (in pixels) can be set to {{typed|text=10}}. It depends on the size of the minimum mapping unit and the smallest object that can be destinguished.
+
* The value for {{button|text=Minimum Segment size}} (in pixels) can be set to {{typed|text=25}}. It depends on the size of the minimum mapping unit and the smallest object that can be destinguished.
 
* Leave all other configurations as they are and click {{button|text=Run}}. Have a look on the resulting filtered and spatial images.
 
* Leave all other configurations as they are and click {{button|text=Run}}. Have a look on the resulting filtered and spatial images.
 
* The Output GIS vector file is specified as a shapefile with the extension *.shp.
 
* The Output GIS vector file is specified as a shapefile with the extension *.shp.
Line 110: Line 133:
 
* Specify the Output vector file. {{button|text=Execute}}
 
* Specify the Output vector file. {{button|text=Execute}}
 
[[File:qgis_otb_vectorClassifier.png|400px]]
 
[[File:qgis_otb_vectorClassifier.png|400px]]
 
=Validation phase=
 
[[Category:QGIS Tutorial]]
 

Latest revision as of 10:54, 15 June 2021

Contents

[edit] Preparation of training data

  • Create a dense regular point grid Vector --> Research tools --> Regular points... with the extent of the multispectral image and a point spacing of 200 meters.
  • Install the Point sampling plugin.
  • Extract the landcover class from an existing thematic classifcation map using the Point Sampling Tool.

Qgis point sampling.png.

  • Select 50 points in each class stratified sampling with equal allocation: Vector --> Resarch tools --> Random section within subsets....

Qgis random selection.png.

  • Rename the class field name to C_ID and change the datatype to int using Processing --> Vector table --> Refactor field.
  • Join the Land use/cover (LUC) class attribute of the selected regular points with the segments (output of Feature extraction). Vector --> Data Management Tools --> Join Attributes by Location ....

Qgis joinLayer.png

  • Interpret the C_ID class by visual interpretation of Google satellite as reference.

[edit] Object-based image analysis (OBIA) with QGIS and OTB processing plugin

[edit] Segmentation

  • In the search engine of Processing Toolbox, type segmentation and double click Segmentation.
  • Set Segmentation algorithm to meanshift
  • Select the input image: Subset_S2A_MSIL2A_20170619T_MUL.tif (data type uint 16bit).
  • The Range radius value can be set to 600. The optimal value depends on datatype dynamic range of the input image and requires experimental trials for the specific classifcation objectives.
  • Set Minimum Region size (in pixels) to 16.
  • Processing mode Vector
  • Set the Mask image to blank (top of dro-down list).
  • The Minimum Segment size (in pixels) can be set to 16 depending on minimum mapping size.
  • Check 8-neighborhood connectivity on.
  • Name the Output vector file e.g. lucc_meanshift_seg.shp. (Filetype shapefile is here mandatory)
  • Click Run.

If no-data are defined in the input image you will get the warning: "this application does not handle no-data". Ignore and load the shapefile with segments manually.

Qgis otb segmentation.png

  • Evaluate the segmentation results: Load the output vector file lucc_meanshift_seg.shp into QGIS on top of the image Subset_S2A_MSIL2A_20170619T_Mul.tif

Mark the vector layer in the Qgis Layers window. Layer --> Properties --> Symbology --> Simple Fill, Fill Style: No Brush and Stroke color:white.

[edit] Feature extraction

In the search engine of Processing Toolbox, type zonalstats and open ZonalStatistics under Image Manipulation of OTB.

  • Select the Input image: Subset_S2A_MSIL2A_20170619T_MUL.tif .
  • Background value to ignore: 65535
  • The input vector data is the result from Segmentation: lucc_meanshift_seg.shp.
  • File name for the output vector data: lucc_meanshift_seg_stats.shp.
  • Click Run.

Otb zonalstats.png

Alternative module:

  • In the search engine of Processing Toolbox, type zonal and double click Zonal Statistics.
  • Select the Raster layer: Subset_S2A_MSIL2A_20170619T_MUL.tif .
  • Set Raster band Band 01.
  • The vector layer containing zones is the result from Segmentation: lucc_meanshift_seg.shp.
  • Change output column prefix to the original Sentinel-2 band name: B1
  • In the list Statistics to calculate just check two measures: Mean and Std. dev..
  • Click Run.

Qgis zonal stats.png

  • Repeat the procedure for bands 02, 03, 04, 05, 06, 07, 08, 09, 10.
  • Open the attribute table of vector layer lucc_meanshift_seg.shp containing now statistics for each zone or segment.

[edit] Training phase

  • In the search engine of Processing Toolbox, type Train and double click TrainVectorClassifier.
  • Name of the input shapefile is train_input_OBIA.shp.
  • Output model filename is lucc_svm_obia.model
  • In the field Field names for training features copy and paste

for OTB 7.0.0 Zonalstatistics module:

 "mean_0 mean_1 stdev_1 mean_2 mean_3 mean_4 mean_5 mean_6 stdev_6 mean_8 stdev_8 mean_9" 

or if you used the qgis zonal statistics module:

 "B1mean B2mean B2stdev B3mean B4mean B5mean B6mean B7mean B7stdev B9mean B9stdev B10mean" 
  • The name of Field containing the class id for supervision" is C_ID.
  • Classifier to use for training: libsvm
  • SVM Kernel Type: linear
  • SVM Model Type: csvc
  • Click Parameters optimizationON.
  • Click Run.

Qgis otb trainvector.png

info.png Info
For more detailed information on the SVM algorithm visit the LibSVM website

[edit] Classification phase

  • In the search engine of Processing Toolbox, type Vector and double click VectorClassifier.
  • Name of the input vector data is lucc_segments.shp.
  • Name of the input model file is lucc_svm_obia.model.
  • Output field containing the class is C_ID
  • Copy and paste into the filed Field names to be calculated the same features as in the TrainVectorClassifier module:

for OTB 7.0.0 Zonalstatistics module:

 "mean_0 mean_1 stdev_1 mean_2 mean_3 mean_4 mean_5 mean_6 stdev_6 mean_8 stdev_8 mean_9" 

or if you used the qgis zonal statistics module:

 "B1mean B2mean B2stdev B3mean B4mean B5mean B6mean B7mean B7stdev B9mean B9stdev B10mean" 
  • Specify the Output vector file. Run

Qgis otb vectorclassifier.png

[edit] Object-based image analysis (OBIA) with OTB standalone

[edit] Segmentation

  • Type into the search box of the Windows taskbar: mapla.bat. Click on mapla.bat to open Monteverdi Application Launcher.
  • In the search engine of mapla, type Segmentation and double click Segmentation.
  • Select the input image: Subset_S2A_MSIL2A_20170619T_MUL.tif (datatype uint 16bits).
  • The Range radius value can be set to 600. The optimal value depends on datatype dynamic range of the input image and requires experimental trials for the specific classifcation objectives.
  • The value for Minimum Segment size (in pixels) can be set to 25. It depends on the size of the minimum mapping unit and the smallest object that can be destinguished.
  • Leave all other configurations as they are and click Run. Have a look on the resulting filtered and spatial images.
  • The Output GIS vector file is specified as a shapefile with the extension *.shp.
  • Click Execute.

Otb segmentation.png

  • Evaluate the segmentation results:

Load the output vector file into QGIS on top of the image Subset_S2A_MSIL2A_20170619T_Mul.tif Mark the vector layer in the Qgis Layers window. Layer --> Properties --> Symbology --> Simple Fill to No Brush and Stroke color to white.

info.png Info
For more detailed information on the SVM algorithm visit the LibSVM website

[edit] Feature extraction

  • In the search engine of Processing Toolbox, type zonal and double click Zonal Statistics.
  • Select the Raster layer: Subset_S2A_MSIL2A_20170619T_MUL.tif .
  • Set Raster band Band 01.
  • The vector layer containing zones is the result from Segmentation: lucc_meanshift_seg.tif.
  • Change output column prefix to the original Sentinel-2 band name: B1
  • In the list Statistics to calculate just check two measures: Mean and Std. dev..
  • Click Run.

Qgis zonal stats.png

  • Repeat the procedure for bands 02, 03, 04, 05, 06, 07, 08, 09 and 10.
  • Open the attribute table of vector layer lucc_meanshift_seg.tif containing now statistics for each zone or segment.

[edit] Training phase

  • In the search engine of mapla, type Train and double click TrainVectorClassifier.
  • Name of the input shapefile is train_input_OBIA.shp.
  • Output model filename is lucc_svm_obia.model
  • In the list Field names for training featrues mark 11 columns: B1mean, B2mean, B2stdev, B3mean, B4mean, B5mean, B6mean, B7mean, B7stdev, B9mean, B9stdev, B10mean with Ctrl + left-click.
  • The name of Field containing the class id for supervision" is C_ID.
  • Classifier to use for training: LibSVM classifier
  • SVM Kernel Type: Linear
  • SVM Model Type: C support vector classification
  • Click Parameters optimizationON.
  • Click Execute.

Qgis otb trainVectorClassifier.png

info.png Info
For more detailed information on the SVM algorithm visit the LibSVM website

[edit] Classification phase

  • In the search engine of mapla, type Vector and double click VectorClassifier.
  • Name of the input vector data is lucc_segments.shp.
  • Name of the input model file is lucc_svm_obia.model.
  • Filed class is C_ID
  • Mark in the list Field names to be calculated the same features as in the TrainVectorClassifier module (see above) using Ctrl + left-click).
  • Specify the Output vector file. Execute

Qgis otb vectorClassifier.png

Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export