Object-based supervised classification

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Feature extraction)
(Feature extraction)
 
(19 intermediate revisions by one user not shown)
Line 2: Line 2:
 
==Segmentation==
 
==Segmentation==
 
* 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'''.
 +
* Select the input image: '''a multispectral Sentinel-2 image''' (data type uint16).
 
* 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 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=16}}.
 
* 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 drop-down list).
* 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'''.
+
* The {{button|text=Minimum object size}} (in pixels) can be set to {{typed|text=16}} depending on  minimum mapping size.
* Name the {{button|text=Output vector file}} e.g. '''lucc_meanshift_seg.gpkg''' (GeoPackage).
+
* Name the {{button|text=Output vector file}} e.g. '''segments_meanshift.shp'''. Extension should be '''.shp''' in this module).
 
* Click {{button|text=Run}}.
 
* Click {{button|text=Run}}.
  
 
[[File:qgis_otb_segmentation.png|400px]]
 
[[File:qgis_otb_segmentation.png|400px]]
  
* Evaluate the segmentation results: Load the output vector file '''lucc_meanshift_seg.gpkg''' into QGIS on top of the image ''Subset_S2A_MSIL2A_20170619T_Mul.tif''
+
* Evaluate the segmentation results: Load the output vector file '''segments_meanshift.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. Right click {{mitem|text=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.
 
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 '''.
+
* Select the Input image: '''a multispectral Sentinel-2 image'''.
* Background value to ignore: {{typed|text=0}}
+
* Background value to ignore: {{typed|text=65535}}
* The input vector data In the {{button|text=Input Vector Data List}} '''do not''' select a vector file from the list of files which might be already loaded in the QGIS Viewer. There is currently a bug in QGIS 3.16 which leads to failure during file import. Instead please select a vector file clicking [[File:Qgis_add_file.png]] and browse directly to the file containing training area polygons in format GPKG or SHP.is the result from Segmentation: '''lucc_meanshift_seg.gpkg'''.
+
* For the {{button|text=Input vector data}} select a vector file with segments (output from Segmentation)
* File name for the output vector data: '''lucc_meanshift_seg_zonal.gpkg'''.
+
* File name for the output vector data: '''segments_stats.gpkg'''.
 
* Click {{button|text=Run}}.
 
* Click {{button|text=Run}}.
 
[[File:otb_zonalstats.png|400px]]
 
[[File:otb_zonalstats.png|400px]]
Line 30: Line 29:
 
==Training phase==
 
==Training phase==
 
* In the search engine of Processing Toolbox, type {{typed|text=Train}} and double click '''TrainVectorClassifier'''.
 
* In the search engine of Processing Toolbox, type {{typed|text=Train}} and double click '''TrainVectorClassifier'''.
* ''Name of the input shapefile'' is {{button|text=lucc_training_obia.gpkg}}.
+
* In the {{button|text=Input Vector Data List}} '''do not''' select a file from the list which is already loaded in the QGIS Viewer. There is currently a bug in QGIS 3.16 which leads to failure during file import. Instead please select a vector file clicking [[File:Qgis_add_file.png]] and browse directly to the file containing training area polygons in format GPKG or SHP e.g. {{button|text=lucc_training_obia.gpkg}}.
* ''Output model filename'' is {{button|text=lucc_svm_obia.model}}
+
* ''Output model filename'' is {{button|text=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  
<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>
+
<pre> "mean_2 stdev_0 mean_9 mean_7 mean_0" </pre>
 +
* This is one of many variable sets as a result of a feature selection procedure.
 
* 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=libsvm}}
 
* Classifier to use for training: {{button|text=libsvm}}
Line 44: Line 44:
  
 
==Classification phase==
 
==Classification phase==
* In the search engine of Processing Toolbox, type {{typed|text=Vector}} and double click '''VectorClassifier'''.
+
* In the search engine of Processing Toolbox, type {{typed|text=VectorClass}} and double click '''VectorClassifier'''.
* Name of the input vector data is {{typed|text=lucc_segments.shp}}.
+
* In the {{button|text=Input Vector Data}} '''do not''' select a file from the list which is already loaded in the QGIS Viewer. There is currently a bug in QGIS 3.16 which leads to failure during file import. Instead please select a vector file clicking [[File:Qgis_add_file.png]] and browse directly to the file containing segments and features for the whole image (result of Feature extaction)training area polygons in format GPKG {{typed|text=segments_meanshift_zonal.gpkg}}.
* Name of the input model file is {{typed|text=lucc_svm_obia.model}}.
+
* Name of the input model file is {{typed|text=svm_obia.model}}.
 
* Output field containing the class is {{typed|text=C_ID}}
 
* 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:
+
* Copy and paste into the field ''Field names to be calculated'' have to be the '''same features''' for prediction as were defined before in the TrainVectorClassifier 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>
+
<pre> "mean_2 stdev_0 mean_9 mean_7 mean_0" </pre>
 +
* Output vector Data file is {{typed|text=lucc_classified_obia.gpkg}}.
 +
{{button|text=Run}}.
 +
 
 
[[File:qgis_otb_vectorclassifier.png|400px]]
 
[[File:qgis_otb_vectorclassifier.png|400px]]
  
=Object-based image analysis (OBIA) with OTB standalone=
+
Load the output vector file manually into QGIS and apply the same QGIS style used for the training data. {{mitem|text=Layer --> Layer properties --> Symbology > Style --> Load style...}}.
==Segmentation==
+
* 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=Segmentation}} and double click '''Segmentation'''.
+
* 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 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.
+
* The Output GIS vector file is specified as a shapefile with the extension *.shp.
+
* Click {{button|text=Execute}}.
+
[[File:otb_segmentation.png|500px]]
+
* 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. {{mitem|text=Layer --> Properties --> Symbology --> Simple Fill}} to ''No Brush'' and {{mitem|text=Stroke color}} to ''white''.
+
{{info|message=Info|text=For more detailed information on the SVM algorithm visit the [http://www.csie.ntu.edu.tw/~cjlin/libsvm/ LibSVM website]}}
+
 
+
==Feature extraction==
+
* 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 '''.
+
* Set Raster band  {{button|text=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: {{typed|text=B1}}
+
* In the list Statistics to calculate just check two measures: '''Mean''' and '''Std. dev.'''.
+
* Click {{button|text=Run}}.
+
[[File:qgis_zonal_stats.png|400px]]
+
* 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.
+
 
+
==Training phase==
+
* In the search engine of mapla, type {{typed|text=Train}} and double click '''TrainVectorClassifier'''.
+
* ''Name of the input shapefile'' is {{button|text=train_input_OBIA.shp}}.
+
* ''Output model filename'' is {{button|text=lucc_svm_obia.model}}
+
* In the list ''Field names for training featrues'' mark 11 columns: {{button|text=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 {{button|text=C_ID}}.
+
* Classifier to use for training: '''LibSVM classifier'''
+
* SVM Kernel Type: '''Linear'''
+
* SVM Model Type: '''C support vector classification'''
+
* Click Parameters optimization{{button|text=ON}}.
+
* Click {{button|text=Execute}}.
+
[[File:Qgis_otb_trainVectorClassifier.png|400px]]
+
{{info|message=Info|text=For more detailed information on the SVM algorithm visit the [http://www.csie.ntu.edu.tw/~cjlin/libsvm/ LibSVM website]}}
+
 
+
==Classification phase==
+
* In the search engine of mapla, 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}}.
+
* Filed class is {{typed|text=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. {{button|text=Execute}}
+
[[File:qgis_otb_vectorClassifier.png|400px]]
+
  
 
[[Category:QGIS Tutorial]]
 
[[Category:QGIS Tutorial]]

Latest revision as of 21:46, 19 June 2021

Contents

[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.
  • Select the input image: a multispectral Sentinel-2 image (data type uint16).
  • Set Segmentation algorithm to meanshift
  • 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 drop-down list).
  • Check 8-neighborhood connectivity on.
  • The Minimum object size (in pixels) can be set to 16 depending on minimum mapping size.
  • Name the Output vector file e.g. segments_meanshift.shp. Extension should be .shp in this module).
  • Click Run.

Qgis otb segmentation.png

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

Mark the vector layer in the Qgis Layers window. Right click 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: a multispectral Sentinel-2 image.
  • Background value to ignore: 65535
  • For the Input vector data select a vector file with segments (output from Segmentation)
  • File name for the output vector data: segments_stats.gpkg.
  • Click Run.

Otb zonalstats.png

[edit] Training phase

  • In the search engine of Processing Toolbox, type Train and double click TrainVectorClassifier.
  • In the Input Vector Data List do not select a file from the list which is already loaded in the QGIS Viewer. There is currently a bug in QGIS 3.16 which leads to failure during file import. Instead please select a vector file clicking Qgis add file.png and browse directly to the file containing training area polygons in format GPKG or SHP e.g. lucc_training_obia.gpkg.
  • Output model filename is svm_obia.model
  • In the field Field names for training features copy and paste
 "mean_2 stdev_0 mean_9 mean_7 mean_0" 
  • This is one of many variable sets as a result of a feature selection procedure.
  • 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 VectorClass and double click VectorClassifier.
  • In the Input Vector Data do not select a file from the list which is already loaded in the QGIS Viewer. There is currently a bug in QGIS 3.16 which leads to failure during file import. Instead please select a vector file clicking Qgis add file.png and browse directly to the file containing segments and features for the whole image (result of Feature extaction)training area polygons in format GPKG segments_meanshift_zonal.gpkg.
  • Name of the input model file is svm_obia.model.
  • Output field containing the class is C_ID
  • Copy and paste into the field Field names to be calculated have to be the same features for prediction as were defined before in the TrainVectorClassifier module:
 "mean_2 stdev_0 mean_9 mean_7 mean_0" 
  • Output vector Data file is lucc_classified_obia.gpkg.

Run.

Qgis otb vectorclassifier.png

Load the output vector file manually into QGIS and apply the same QGIS style used for the training data. Layer --> Layer properties --> Symbology > Style --> Load style....

Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export