Object-based classification (Tutorial)
(→Object-based classifcation using SVM algorithm) |
|||
Line 3: | Line 3: | ||
== Mean-shift segmentation of large size images == | == Mean-shift segmentation of large size images == | ||
− | # Step. Perform a mean shift filtering on the preprocessed input image '' | + | # Step. Perform a mean shift filtering on the preprocessed input image ''Subset_S2A_MSIL2A_20170619T_B12_BOA.tif''. 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 '' | + | ##* Set the ''Subset_S2A_MSIL2A_20170619T_B12_BOA'' layer as {{button|text=Input image}}. |
##* Increase the ''Available RAM (Mb)'' according to your system to speed up the process. | ##* Increase the ''Available RAM (Mb)'' according to your system to speed up the process. | ||
##* The {{button|text=Range radius}} should be set to 30. | ##* The {{button|text=Range radius}} should be set to 30. | ||
Line 15: | Line 15: | ||
##* 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. | ##* 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. 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)}}. | # Step. 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='' | + | ##* The ''Input image'' is the {{button|text=''Subset_S2A_MSIL2A_20170619T_B12_BOA''}} layer. |
##* The ''Segmented image'' is {{button|text=Output image}} from step 2. | ##* The ''Segmented image'' is {{button|text=Output image}} from step 2. | ||
##* The {{button|text=Minimum Region size}} is set to 10. | ##* The {{button|text=Minimum Region size}} is set to 10. | ||
##* Leave all other configurations as they are and click {{button|text=Run}}. | ##* Leave all other configurations as they are and click {{button|text=Run}}. | ||
# Step. 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}} | # Step. 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= | + | ##* The ''Input image'' is the {{button|text=Subset_S2A_MSIL2A_20170619T_B12_BOA}} layer. |
##* ''Segmented image'' is {{button|text=Output image}} from step 3. | ##* ''Segmented image'' is {{button|text=Output image}} from step 3. | ||
− | ##* The name of ''Output GIS vector file'' is {{button|text= | + | ##* The name of ''Output GIS vector file'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp}} |
##* For the rest of parameters keep default values.{{button|text=Run}}. | ##* 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 '' | + | 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 ''Subset_S2A_MSIL2A_20170619T_B12_BOA.tif'' to evaluate the segmentation result. |
== Preparation of reference data == | == Preparation of reference data == | ||
Line 30: | Line 30: | ||
##* The ''Target vector file'' is the {{button|text=Output GIS vector file}} of step 4. | ##* The ''Target vector file'' is the {{button|text=Output GIS vector file}} of step 4. | ||
##* ''Join vector layer'' is {{button|text=training_manual_poly.shp}}. | ##* ''Join vector layer'' is {{button|text=training_manual_poly.shp}}. | ||
− | ##* ''Output vector'' {{button|text= | + | ##* ''Output vector'' {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.shp}}. |
##* For the rest of parameters keep default values.{{button|text=OK}}. | ##* For the rest of parameters keep default values.{{button|text=OK}}. | ||
Rename the field names of the resulting output vector attribut table avoiding upper capitals and underline using the ''Table Manager'' plugin. Rename the attribut field ''C_ID'' to ''class''. | Rename the field names of the resulting output vector attribut table avoiding upper capitals and underline using the ''Table Manager'' plugin. Rename the attribut field ''C_ID'' to ''class''. | ||
Line 38: | Line 38: | ||
{{mitem|text=Start --> All Programs --> OSGeo4W --> OSGeo4W Shell}} or double click on the file ''C:\OSGeo4W64\OSGeo4W.bat''. | {{mitem|text=Start --> All Programs --> OSGeo4W --> OSGeo4W Shell}} or double click on the file ''C:\OSGeo4W64\OSGeo4W.bat''. | ||
# A windows command shell opens, please type ''otbgui_ComputeOGRLayersFeaturesStatistics''. | # A windows command shell opens, please type ''otbgui_ComputeOGRLayersFeaturesStatistics''. | ||
− | ##* ''Name of the input vector'' is {{button|text= | + | ##* ''Name of the input vector'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.shp}}. |
− | ##* ''XML file containing mean and variance of each feature'' is {{button|text= | + | ##* ''XML file containing mean and variance of each feature'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.xml}}. |
− | ##* In the ''List of features to consider for statistics'' mark the columns {{button|text=meanB0, meanB1, meanB2}}.{{button|text=Execute}}. Calculate also an XML file for vector file {{button|text= | + | ##* In the ''List of features to consider for statistics'' mark the columns {{button|text=meanB0, meanB1, meanB2}}.{{button|text=Execute}}. Calculate also an XML file for vector file {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp}}. |
# Type into the OSGeo4W shell ''otbgui_TrainOGRLayersClassifier''. | # Type into the OSGeo4W shell ''otbgui_TrainOGRLayersClassifier''. | ||
− | ##* ''Name of the input shapefile'' is {{button|text= | + | ##* ''Name of the input shapefile'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.shp}}. |
− | ##* ''XML file containing mean and variance of each feature'' is {{button|text= | + | ##* ''XML file containing mean and variance of each feature'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.xml}}. |
− | ##* ''Output model filename'' is {{button|text= | + | ##* ''Output model filename'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.model}} |
− | ##* In the ''List of features to consider for statistics'' mark the columns {{button|text=meanB0, meanB1, meanB2}}. | + | ##* In the ''List of features to consider for statistics'' mark the columns {{button|text=meanB0, meanB1, meanB2, ..}}. |
##* The name of''Field containing the class id for supervision" is {{button|text=class}}.{{button|text=Execute}}. | ##* The name of''Field containing the class id for supervision" is {{button|text=class}}.{{button|text=Execute}}. | ||
# Type into the OSGeo4W shell ''otbgui_OGRLayerClassifier''. | # Type into the OSGeo4W shell ''otbgui_OGRLayerClassifier''. | ||
− | ##* ''Name of the input shapefile'' is {{button|text= | + | ##* ''Name of the input shapefile'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp}}. |
− | ##* ''XML file containing mean and variance of each feature'' is {{button|text= | + | ##* ''XML file containing mean and variance of each feature'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.xml}}. |
− | ##* ''Input model filename'' is {{button|text= | + | ##* ''Input model filename'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.model}} |
− | ##* In the ''List of features to consider for statistics'' mark the columns {{button|text=meanB0, meanB1, meanB2}}. | + | ##* In the ''List of features to consider for statistics'' mark the columns {{button|text=meanB0, meanB1, meanB2, ..}}. |
##* The name of''Field containing the predicted class" is {{button|text=predicted}}.{{button|text=Execute}}. | ##* The name of''Field containing the predicted class" is {{button|text=predicted}}.{{button|text=Execute}}. | ||
# Open the resulting vector file in a QGIS map view. | # Open the resulting vector file in a QGIS map view. | ||
##* Change the style of the classified vector layer: Go to {{mitem|text=layer properties --> style}}. Click on ‘Load Style’. Browse for ''OBIA_legend'' file and select ''OBIA_legend.qml''}}. {{button|text=apply}}, {{button|text=OK}}. | ##* Change the style of the classified vector layer: Go to {{mitem|text=layer properties --> style}}. Click on ‘Load Style’. Browse for ''OBIA_legend'' file and select ''OBIA_legend.qml''}}. {{button|text=apply}}, {{button|text=OK}}. | ||
# Simplify the vector file using {{mitem|text=Vector --> Geoprocessing Tools --> Dissolve...}} | # Simplify the vector file using {{mitem|text=Vector --> Geoprocessing Tools --> Dissolve...}} | ||
− | ##* ''Input vector layer'' is {{button|text= | + | ##* ''Input vector layer'' is {{button|text=seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp}}. |
##* ''Dissolve field'' is {{button|text=predicted}}. | ##* ''Dissolve field'' is {{button|text=predicted}}. | ||
− | ##* ''Output shapefile'' is {{button|text= | + | ##* ''Output shapefile'' is {{button|text=seg_188_Subset_S2A_MSIL2A_20170619T_B12_BOA_diss.shp}} |
Revision as of 09:22, 18 December 2017
Contents |
Determining segmentation parameters
Mean-shift segmentation of large size images
- Step. Perform a mean shift filtering on the preprocessed input image Subset_S2A_MSIL2A_20170619T_B12_BOA.tif. We extract homogeneous objects on the basis of a filtered image. Go to Processing-Toolbox --> Orfeo Toolbox (image analysis) --> Image Filtering --> Exact Large-Scale Mean-Shift segmentation, step 1 (Smoothing).
- Set the Subset_S2A_MSIL2A_20170619T_B12_BOA layer as Input image.
- Increase the Available RAM (Mb) according to your system to speed up the process.
- The Range radius should be set to 30.
- Leave all other configurations as they are and click Run. Have a look on the resulting filtered and spatial images.
- Step. Convert the filtered image to one band image object. Go to Processing-Toolbox --> Orfeo Toolbox (image analysis) --> Segmentation --> Exact Large-Scale Mean-Shift segmentation, step 2.
- The Filtered image is Filter output from step 1.
- Leave the Spatial image as [not selected].
- Range radius is set to 30.
- Define a path to the Directory where to write temporary files.
- Leave all other configurations as they are and click 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. Adjust the image object size merging small regions with the module Processing-Orfeo Toolbox (image analysis) --> Segmentation-Exact --> Large-Scale Mean-Shift segmentation, step 3 (optional).
- The Input image is the Subset_S2A_MSIL2A_20170619T_B12_BOA layer.
- The Segmented image is Output image from step 2.
- The Minimum Region size is set to 10.
- Leave all other configurations as they are and click Run.
- Step. 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.Processing-Orfeo Toolbox (image analysis) --> Segmentation-Exact Large-Scale Mean-Shift segmentation, step 4
- The Input image is the Subset_S2A_MSIL2A_20170619T_B12_BOA layer.
- Segmented image is Output image from step 3.
- The name of Output GIS vector file is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp
- For the rest of parameters keep default values.Run.
Change Layer --> Properties Style --> Fill Style to No Brush and Colors --> Border to white. Overlay the vector file on top of the image Subset_S2A_MSIL2A_20170619T_B12_BOA.tif to evaluate the segmentation result.
Preparation of reference data
Join the Land use/cover (LUC) class attribute of manually digitized training areas with the image segments. Vector --> Data Management Tools --> Join Attributes by Location ....
- The Target vector file is the Output GIS vector file of step 4.
- Join vector layer is training_manual_poly.shp.
- Output vector seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.shp.
- For the rest of parameters keep default values.OK.
Rename the field names of the resulting output vector attribut table avoiding upper capitals and underline using the Table Manager plugin. Rename the attribut field C_ID to class.
Object-based classifcation using SVM algorithm
The vector based supervised classifcation modules in QGIS 2.12.3 are under development and still not working. Alternativly, we may use the windows command line and OTB QT graphical user interfaces. Start --> All Programs --> OSGeo4W --> OSGeo4W Shell or double click on the file C:\OSGeo4W64\OSGeo4W.bat.
- A windows command shell opens, please type otbgui_ComputeOGRLayersFeaturesStatistics.
- Name of the input vector is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.shp.
- XML file containing mean and variance of each feature is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.xml.
- In the List of features to consider for statistics mark the columns meanB0, meanB1, meanB2.Execute. Calculate also an XML file for vector file seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp.
- Type into the OSGeo4W shell otbgui_TrainOGRLayersClassifier.
- Name of the input shapefile is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.shp.
- XML file containing mean and variance of each feature is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.xml.
- Output model filename is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.model
- In the List of features to consider for statistics mark the columns meanB0, meanB1, meanB2, ...
- The name ofField containing the class id for supervision" is class.Execute.
- Type into the OSGeo4W shell otbgui_OGRLayerClassifier.
- Name of the input shapefile is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp.
- XML file containing mean and variance of each feature is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.xml.
- Input model filename is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA_train.model
- In the List of features to consider for statistics mark the columns meanB0, meanB1, meanB2, ...
- The name ofField containing the predicted class" is predicted.Execute.
- Open the resulting vector file in a QGIS map view.
- Change the style of the classified vector layer: Go to layer properties --> style. Click on ‘Load Style’. Browse for OBIA_legend file and select OBIA_legend.qml}}. apply, OK.
- Simplify the vector file using Vector --> Geoprocessing Tools --> Dissolve...
- Input vector layer is seg_Subset_S2A_MSIL2A_20170619T_B12_BOA.shp.
- Dissolve field is predicted.
- Output shapefile is seg_188_Subset_S2A_MSIL2A_20170619T_B12_BOA_diss.shp
- Info
- For more detailed information on the SVM algorithm visit the library website