Object-based classification (Tutorial)

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Feature extraction)
 
(129 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
==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.
  
== Determining segmentation parameters ==
+
=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.
  
== Mean-shift segmentation of large size images ==
+
[[File:qgis_otb_segmentation.png|400px]]
# Step. We perform a mean shift filtering on the preprocessed input image ''188_pca_cmask_8b.tif''. (3 principal components of Landsat-8 multispectral bands (B1 - B7), pansharpened with band B8, rescaled to 8bit. Clouds and cloud shadows are masked). We extract homogeneous objects on the basis of a filtered image. Go to {{mitem|text=Processing-Toolbox --> Orfeo Toolbox (image analysis) --> Image Filtering --> Exact Large-Scale Mean-Shift segmentation, step 1 (Smoothing)}}.
+
##* Set the ''188_pca_cmask_8b'' layer as {{button|text=Input image}}.
+
##* The {{button|text=Range radius}} should be set to 30.
+
##* Leave all other configurations as they are and click {{button|text=Run}}. Have a look on the resulting filtered and spatial images.
+
# Step. We convert the filtered image to one band image object. Go to {{mitem|text=Processing-Toolbox --> Orfeo Toolbox (image analysis) --> Segmentation --> Exact Large-Scale Mean-Shift segmentation, step 2}}.
+
##* The ''Filtered image'' is {{button|text=Filter output}} from step 1.
+
##* Leave the ''Spatial image'' as {{button|text= [not selected]}}.
+
##* {{button|text=Range radius}} is set to 30.
+
##* Leave all other configurations as they are and click {{button|text=Run}}. The Output image is a labeled image where neighbor pixels whose range distance is below range radius will be grouped together into the same cluster.
+
# Step. We adjust the image object size merging small regions with the module {{mitem|text=Processing-Orfeo Toolbox (image analysis) --> Segmentation-Exact --> Large-Scale Mean-Shift segmentation, step 3 (optional)}}.
+
##* The ''Input image'' is the {{button|text=''188_pca_cmask_8b''}} layer.
+
##* The ''Segmented image'' is {{button|text=Output image}} from step 2.
+
##* The {{button|text=Minimum Region size}} is set to 10.
+
##* Leave all other configurations as they are and click {{button|text=Run}}.
+
# Step. We convert the image segments from raster to polygon vectors. Label ID, mean and standard deviation, number of the pixels in an image polygon are calculated and added as additional columns in the resulting shapefile.{{mitem|text=Processing-Orfeo Toolbox (image analysis) --> Segmentation-Exact Large-Scale Mean-Shift segmentation, step 4}}
+
##* The ''Input image'' is the {{button|text=188_pca_cmask_8b}} layer.
+
##* ''Segmented image'' is  {{button|text=Output image}} from step 3.
+
##* The name of ''Output GIS vector file'' is {{button|text=1seg_188_pca_cmask_8b.shp}}
+
##* For the rest of parameters keep default values.{{button|text=Run}}.
+
Change {{mitem|text=Layer --> Properties Style --> Fill Style}} to ''No Brush'' and {{mitem|text=Colors --> Border}} to white. Overlay the vector file on top of the image ''188_pca_cmask_8b.tif'' to evaluate the segmentation result.
+
  
== Preparation of reference data ==
+
* 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''.
  
 +
==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'''.
 +
* 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.
  
== Object-based classifcation using SVM algorithm ==
+
==Training phase==
{{info|message=Info|text=For more detailed information on the SVM algorithm visit the [http://www.csie.ntu.edu.tw/~cjlin/libsvm/ library website]}}
+
* 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]}}
  
# 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.
+
==Classification phase==
# 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}}.
+
* In the search engine of Processing Toolbox, type {{typed|text=Vector}} and double click '''VectorClassifier'''.
# 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 vector data is {{typed|text=lucc_segments.shp}}.
# 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.  
+
* Name of the input model file is {{typed|text=lucc_svm_obia.model}}.
# 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.
+
* Output field containing the class is {{typed|text=C_ID}}
# 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}}.
+
* Copy and paste into the filed ''Field names to be calculated'' the '''same features''' as in the TrainVectorClassifier 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. 
+
for OTB 7.0.0 Zonalstatistics module:
# 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.
+
<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>
# 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 {{button|text=Calculate error matrix}} (see figure '''E'''). {{red|text=We did all of this in [[Exercise 08: Supervised classification|ecercise 08]]. Shouldn't we just link there? [[User:Lburgr|- Levent]] ([[User talk:Lburgr|talk]])}}
+
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]]
  
{|class="wikitable" style="border:0pt"
+
=Object-based image analysis (OBIA) with OTB standalone=  
|style="border:0pt"|[[Image:RemSens_Exercise10_01.jpg|thumb|450px|'''Figure C''': Result of segmentation by mean shift clustering with the Orfeo Toolbox Mean Shift Segmentation algorithm]]
+
==Segmentation==
|style="border:0pt"|[[Image:RemSens_Exercise08_04.png|thumb|450px|'''Figure D''': Result of the semi-automatic maximum likelihood classification]]
+
* 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'''.
|style="border:0pt"|[[Image:RemSens_Exercise08_05.png|thumb|450px|'''Figure D''': Error matrix for the semi-automatic maximum likelihood classification]]
+
* 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]}}
  
== Alternative supervised classification with Support Vector Machine (SVM) ==
+
==Feature extraction==
# Start Monteverdi.
+
* In the search engine of Processing Toolbox, type {{typed|text=zonal}} and double click '''Zonal Statistics'''.
# Open ''188_pca_indices_pan_mean.tif'' and ''train_segments_7class.shp'' in Monteverdi via {{mitem|text=File --> Open dataset}}.  
+
* Select the Raster layer: '''Subset_S2A_MSIL2A_20170619T_MUL.tif '''.
# Go to {{mitem|text=Learning --> SVM classification (EXPERIMENTAL)}}
+
* Set Raster band  {{button|text=Band 01}}.
# 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}}.
+
* The vector layer containing zones is the result from Segmentation: '''lucc_meanshift_seg.tif'''.
# Specify the {{button|text=Class key}} as {{button|text=ID_class}} and click {{button|text=Train}}. A classification output is seen Monteverdi.
+
* Change output column prefix to the original Sentinel-2 band name: {{typed|text=B1}}
# Click {{button|text=Validate}} to see classification accuracy and {{button|text=Calculate error matrix}}. See Figure '''G'''.
+
* 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.
  
[[file:Monteverdi_Supervised_Error_Matrix.jpg|thumb|center|450px|Supervised classification menu in Monteverdi with error matrix]]
+
==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]}}
  
[[Category:Image classification]]
+
==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]]

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