Object-based classification (Tutorial)

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Feature extraction)
 
(165 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{construction}}
+
==Preparation of training data==
 +
* Create a dense regular point grid {{mitem|text=Vector  --> Research tools --> Regular points...}} with the extent of the multispectral image and a point spacing of {{typed|text=200}} meters.
 +
* Install the Point sampling plugin.
 +
* Extract the landcover class from an existing thematic classifcation map using the Point Sampling Tool.
 +
[[File:qgis_point_sampling.png|300px]].
 +
* Select 50 points in each class stratified sampling with equal allocation: {{mitem|text=Vector  --> Resarch tools --> Random section within subsets...}}.
 +
[[File:qgis_random_selection.png|300px]].
 +
* Rename the class field name to '''C_ID''' and change the datatype to '''int''' using {{mitem|text=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). {{mitem|text=Vector  --> Data Management Tools --> Join Attributes by Location ...}}.
 +
[[File:qgis_joinLayer.png|400px]]
 +
* Interpret the C_ID class by visual interpretation of Google satellite as reference.
  
:''This exercise is part of the [[QGIS Tutorial 2013/14]]''
+
=Object-based image analysis (OBIA) with QGIS and OTB processing plugin=
 +
==Segmentation==
 +
* In the search engine of Processing Toolbox, type {{typed|text=segmentation}} and double click '''Segmentation'''.
 +
* 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.
 +
* Set {{button|text=Minimum Region size}} (in pixels) to {{typed|text=16}}.
 +
* {{button|text=Processing mode}} '''Vector'''
 +
* 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=16}} depending on  minimum mapping size.
 +
* Check {{button|text=8-neighborhood connectivity}} on.
 +
* Name the {{button|text=Output vector file}} e.g. '''lucc_meanshift_seg.shp'''. (Filetype shapefile is here mandatory)
 +
* 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.
  
== Determining segmentation parameters ==
+
[[File:qgis_otb_segmentation.png|400px]]
# Start Monteverdi
+
# Open dataset in Monteverdi: {{mitem|text=File --> Open dataset}} e.g. ''188_pca_indices_pan.tif''
+
# Subset data to a small area: {{mitem|text=File --> Extract ROI from dataset}}, in the field {{mitem|text=Image to read --> Reader0}} select a file e.g. ''188_pca_indices_pan.tif'' and press {{button|text=OK}}
+
# Drag the mouse in the {{button|text=Select the ROI}} window to select a region equivalent to 500x500 pixels and press {{button|text=OK}} to make an output image. You can name it ''ExtractROI1''. {{red|text=Not sure if this is to be the file name or a button pressed. [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}
+
# To perform the mean shift segmentation: {{mitem|text=Filtering --> Mean shift clustering}}, in the field {{button|text=Image to apply shift on}} select the output image from step 4. The Mean shift module window opens. Set the following parameters.
+
#* {{button|text=Spatial radius}} = {{typed|text=5}}
+
#* {{button|text=Spectral values}} = {{typed|text=0.5}},
+
#* {{button|text=Min region size}} = {{typed|text=57}}.
+
#* Check the boxes {{button|text=Display Boundaries}} and {{button|text=Display cluster}} {{red|text=I assume these are check boxes? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}
+
# Confirm with {{button|text=Run}}. An output named ''Labeled image'' is created (Figure '''A''') {{red|text=Is this right? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}.
+
# Finally click {{button|text=Close}} to create all the output in Monteverdi window.
+
  
{{red|text=Figure A: Mean Shift Module}}
+
* 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''.
  
== Object labeling and segmentation via SVM ==
+
==Feature extraction==
# Object labeling: Go to {{mitem|text=Learning --> Object Labeling}}, in the field {{button|text=The image to classify}} select file generated in the previous step and in the field {{button|text=The segmentation of the image}} select file {{mitem|text=MeanShift1 --> Labeled Image}} and press {{button|text=OK}} {{red|text=Correct? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}. A window {{mitem|text=Object Labeling}} opens.  
+
In the search engine of Processing Toolbox, type {{typed|text=zonalstats}} and open '''ZonalStatistics''' under Image Manipulation of OTB.
# Click Add to start object labeling. A new class appears in the {{button|text=Objects}} tab in the upper right corner of the window. Specify color red for {{button|text=New Class 0 = Urban}}.  Double right click the image to select {{typed|text=10}} urban objects as visually intepreted. Repeat the same procedure for {{button|text=New Class 1 = Cropland}} in yellow color and {{button|text=New Class 2 = Forest}} in green color.
+
* Select the Input image: '''Subset_S2A_MSIL2A_20170619T_MUL.tif '''.
# To select shape and pixel parameters for object clustering: In the {{button|text=Features}} tab check {{button|text=STATS::Band1::Mean}}, {{button|text=STATS::Band2::Mean}}, {{button|text=STATS::Band3::Mean}} {{red|text=-- are these really the names of the boxes? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}
+
* Background value to ignore: {{typed|text=65535}}
# To selecti Support Vector Machine (SVM) parameters: Leave the other parameters to default and check the {{button|text=Parameters optimization}} box. Click {{button|text=classify}} to obtain the output displayed in Figure '''B'''. Using the {{button|text=Opacity}} slide, you can compare the output with the original image. Note the accuracy measure in the lower right side of the window.  
+
* The input vector data is the result from Segmentation: '''lucc_meanshift_seg.shp'''.
# Try other Features by checking them in the {{button|text=Features}} tab and compare output clusters with the output of parameters specified at step 3.
+
* File name for the output vector data: '''lucc_meanshift_seg_stats.shp'''.
 +
* Click {{button|text=Run}}.
 +
[[File:otb_zonalstats.png|400px]]
  
{{info|message=Info|text=For more detailed information on the SVM algorithm visit the [http://www.csie.ntu.edu.tw/~cjlin/libsvm/ library website]}}
+
Alternative module:
 +
* 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.shp'''.
 +
* 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, 10.
 +
* Open the attribute table of vector layer '''lucc_meanshift_seg.shp''' containing now statistics for each zone or segment.
  
{{red|text=Figure B: SVM output}}
+
==Training phase==
 +
* In the search engine of Processing Toolbox, 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 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>
 +
* The name of ''Field containing the class id for supervision" is {{button|text=C_ID}}.
 +
* Classifier to use for training: {{button|text=libsvm}}
 +
* SVM Kernel Type: {{button|text=linear}}
 +
* SVM Model Type: {{button|text=csvc}}
 +
* Click Parameters optimization{{button|text=ON}}.
 +
* Click {{button|text=Run}}.
 +
[[File:qgis_otb_trainvector.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]}}
  
== Object based segmentation by mean shift clustering ==
+
==Classification phase==
# Load the raster map ''188_pca_indices_pan.tif'' provided in the [[course data]]. Open {{button|text=Mean Shift Segmentation (Large scale, vector output)}} from the Orfeo toolbox algorithms in the {{button|text=Processing}} bar.
+
* In the search engine of Processing Toolbox, type {{typed|text=Vector}} and double click '''VectorClassifier'''.
# Select ''188_pca_indices_pan.tif'' as input image. Change {{button|text=Range radius}} to 0.5 and {{button|text=Min Region size}} to 50. Specify the output file as ''Segments_all.shp'' and click {{button|text=RUN}}.
+
* Name of the input vector data is {{typed|text=lucc_segments.shp}}.
# Load ''Segments_all.shp'' to the project. To view both the vector segments and the underlying image file, visualize the segments as hollow polygons: Right click on ''Segments_all.shp'' in the [[TOC]],  and select {{mitem|text=Properties --> Style}} and select {{button|text=Fill-Simple fill}} with {{button|text=No brush}} as {{button|text=Fill style}}. Change the border outline colour to white for better visibility (see figure '''C''').
+
* Name of the input model file is {{typed|text=lucc_svm_obia.model}}.
# Split the multiband image ''188_pca_indices_ pan_mean.tif'' to single band rasters. This step is necessary to allow extraction of individual segment spectral values using the zonal statistics tool as shown in step 5: Open {{mitem|text=Split image}} tool from the Orfeo toolbox. Select {{mitem|text=Image manipulation --> Split image}} and specify output image.  
+
* Output field containing the class is {{typed|text=C_ID}}
# To extract pixel spectral data for each object using the Zonal statistics Plugin: Install Zonal Statistics Plugin from the {{mitem|text=Plugins --> Manage and Install plugins}} menu. Select {{button|text=Get more}} and browse for the {{button|text=Zonal statistics plugin}}. After successfully installing the tool, open it from {{mitem|text=Raster --> Zonal statistics --> Zonal statistics}} and specify the Raster layer, Polygon layer containing the zones and Output column for Bands 1, 2 and 3 respectively.
+
* Copy and paste into the filed ''Field names to be calculated'' the '''same features''' as in the TrainVectorClassifier module:
# Rasterize the segments to prepare for classification: Open the Rasterization tool from the Orfeo tool box, selecting {{mitem|text=Vector Data Manipulation --> Rasterization}}. Select ''Segments_all.shp'' as {{button|text=Input vector dataset}}. Select ''188_pca_indices_pan_mean.tif'' as {{button|text=Input reference image}}. Also enter the input coordinates  {{button|text=Output Upper-left x}} and {{button|text=Output Upper-left y}}. The coordinates can be found in the {{button|text=Metadata}} tab of the layer {{button|text=Properties}}. Change {{button|text=Spacing (GSD)x}} and {{button|text=Spacing (GSD)y}} spacing to 15 and {{button|text=Rasterization mode}} to attribute. Specify the output file and click {{button|text=RUN}}.
+
for OTB 7.0.0 Zonalstatistics module:
# To collect training objects for the Object based Supervised Maximum Likelihood Classification: Select 210 random objects from ''Segment_all.shp'' using the random selection tool {{mitem|text=Vector --> Research Tools --> Random selection}}. Set {{button|text=Number of Features}} to 210. Press {{button|text=OK}}. Right click the layer ''Segment_all.shp'' and {{button|text=Save selected objects}} as ''210_selected.shp''. Load the new shapefile into QGIS. 
+
<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>
# Specify the class for each object in ''210_selected.shp'' file according to table '''A''' {{red|text=Where do I find this? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}. This is the training dataset for maximum likelihood classification. Load a Google Maps Image from the OpenLayers plugin: {{mitem|text= Plugins --> OpenLayers plugin --> Add Google Satellite layer}}. Install the {{button|text=QuickMultiAttributeEdit}} plugin. The tool simply helps in editing attributes of a vector file without opening the attribute table. Open the tool from {{mitem|text=Plugins --> QuickMultiAttributeEdit}}.  Right click ''210_selected.shp'' and open the attribute table. Toogle the editing mode. Select one row i.e. one segment by clicking {{button|text=Zoom map to the selected row}}, identify the land use type by corroborating with google imagery. Press {{button|text=F12}} key to open the {{button|text=QuickMultiAttributeEdit}} and set the {{button|text=IDClass}} corresponding to the Class Code in Table '''A'''. Repeat this procedure for each segment.
+
or if you used the qgis zonal statistics module:  
# Perform maximum likelihood classification of the object segments using the {{button|text=Semiautomatic classification plugin}}: To open the plugin go to {{mitem|text=Raster --> Semi-Automatic Classification Plugin --> Semi-Automatic Classification Plugin}}. Click {{button|text=Show docks}}. In the {{button|text=Semi-Automatic:ROI creation}} window select {{button|text=input}} as 188_pca_indices_ pan_mean.tif., {{button|text=Select a training shapefile}} as train_segments_6class.shp. Leave the ROI parameters to default. In the Semi-Automatic: Classification window {{button|text=select classification algorithm}} to Maximum Likelihood, {{button|text=select qml}} as ''classification.qml''. Check {{button|text=Create vector}}, {{button|text=Apply mask}}, {{button|text=Classification report}} and {{button|text=Calculate accuracy}}. Specify a cloud mask as ''cloud_mask.shp''. Click {{button|text=Perform Classification}} and specify the output file as ''semi_automatic classification.shp''. An additional output file ''semi_automatic classification.tif'' will be created.  See Figure '''D'''. Import the classification style from ''classification.qml''.  To conduct an accuracy assessment for your map output, go to the {{button|text=Post processing}} tab and select {{button|text=Accuracy}} in the Semi-Automatic Classification Plugin window.  Load ''semi_automatic_classification.tif'' in {{button|text=Select the classification to assess}} and ''train_segments_6class.shp'' in {{button|text=Select the reference shapefile}} and click
+
<pre> "B1mean B2mean B2stdev B3mean B4mean B5mean B6mean B7mean B7stdev B9mean B9stdev B10mean" </pre>
{{button|text=Calculate error matrix}} (see figure '''E'''). {{red|text=Didn't we do this in the preceding lesson? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}
+
* Specify the Output vector file. {{button|text=Run}}
 +
[[File:qgis_otb_vectorclassifier.png|400px]]
  
{{red|text=Figure C: QGIS Mean shift Clustering Segmentation.}}  
+
=Object-based image analysis (OBIA) with OTB standalone=
 +
==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]}}
  
{{red|text=Figure D: Supervised Maximum Likelihood Classification}}
+
==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.
  
{{red|text=Figure E: Supervised Maximum Likelihood Classification Accuracy}}
+
==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]}}
  
== Alternative supervised classification with Support Vector Machine (SVM) ==
+
==Classification phase==
# Start Monteverdi.
+
* In the search engine of mapla, type {{typed|text=Vector}} and double click '''VectorClassifier'''.
# Open ''188_pca_indices_pan_mean.tif'' and ''train_segments_7class.shp'' in Monteverdi via {{mitem|text=File --> Open dataset}}.
+
* Name of the input vector data is {{typed|text=lucc_segments.shp}}.
# Go to {{mitem|text=Learning --> SVM classification (EXPERIMENTAL)}}
+
* Name of the input model file is {{typed|text=lucc_svm_obia.model}}.
# Load ''188_pca_indices_pan_mean.tif'' as {{button|text=Input image}} and ''train_segments_7class.shp'' as {{button|text=Training/validation ROIs}} and press {{button|text=OK}}.
+
* Filed class is {{typed|text=C_ID}}
# Specify the {{button|text=Class key}} as {{button|text=ID_class}} and click {{button|text=Train}}. A classification output is seen Monteverdi.
+
* Mark in the list ''Field names to be calculated'' the '''same features''' as in the TrainVectorClassifier module (see above) using Ctrl + left-click).
# Click {{button|text=Validate}} to see classification accuracy and {{button|text=Calculate error matrix}}.  See Figure '''G'''.
+
* Specify the Output vector file. {{button|text=Execute}}
 
+
[[File:qgis_otb_vectorClassifier.png|400px]]
{{red|text=Figure F: Perform an alternative supervised classification using Support Vector Machines in Monteverdi (Experimental for large datasets)}}
+
 
+
{{red|text=Figure G: SVM classification accuracy}}
+

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