Supervised classification (Tutorial)

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
Line 2: Line 2:
 
''In this article, you will learn how to conduct a supervised image classification in [[QGIS]]''
 
''In this article, you will learn how to conduct a supervised image classification in [[QGIS]]''
  
== Plugin installation and testing ==
+
== Classification with Orfeo Toolbox ==
 +
=== Zonal Statistics ===
 +
# Add the LandSat-8 imagery ''SUB_LC81950242013188LGN00_MUL.tif'' into a QGIS project. It should be available in the course data.
 +
# Calculate mean and standard error for each band of the LandSat-8 imagery.
 +
## Open {{mitem|text=Orfeo Toolbox --> Compute images second order statistics}} (see figure '''A''').
 +
## Set ''SUB_LC81950242013188LGN00_MUL.tif'' as {{button|text=Input images}}.
 +
## Save the {{button|text=Output XML file}} as ''SUB_LC81950242013188LGN00_mul.tif.xml''.
 +
 
 +
=== Train image classifier ===
 +
# Add the training areas ''training_manual_poly.shp'' into QGIS. It should be available in the course data.
 +
# Open {{mitem|text=Orfeo Toolbox --> TrainImageClassifier (libsvm)}} to use the Support Vector Machine SVM algorithm (see figure '''B''').
 +
# Set ''SUB_LC81950242013188LGN00_MUL.tif'' as {{button|text=Input image list}}.
 +
# Set ''training_manual_poly.shp'' as {{button|text=Input vector list}}.
 +
# Set ''SUB_LC81950242013188LGN00_mul.tif.xml'' as {{button|text=Input XML image statistics file}}.
 +
# Set {{button|text=Name of discrimination field}} to ''C_ID'' (C_ID refers to the column that contain the LUC classes code).
 +
# Save the {{button|text=Output confusion matrix}} as ''ConfusionMatrixSVM.csv''.
 +
# Save the {{button|text=Output model}} as ''SVM.model''.
 +
# Calculation of accuracies :<br/> Open ''ConfusionMatrixSVM.csv'' in LibreOffice or MS Excel and calculate overall, producer’s and user’s accuracies.
 +
 
 +
=== Classification of the LandSat-8 imagery ===
 +
# Add the cloud mask ''cloud_shadow_mask.tif'' into QGIS. It should be available in the course data.
 +
# Open {{mitem|text=Orfeo Toolbox --> Image Classification}} (see figure '''C''').
 +
# Set ''SUB_LC81950242013188LGN00_MUL.tif'' as {{button|text=Input image}}.
 +
# Set ''cloud_shadow_mask.tif'' as {{button|text=Input mask}}.
 +
# Set ''SVM.model'' as {{button|text=Model file}}.
 +
# Set ''SUB_LC81950242013188LGN00_MUL.tif.xml'' as {{button|text=Statistical file}}.
 +
# Save the {{button|text=Output image}} as ''su_svm.tif''.
 +
# Evaluate classification results.
 +
## Add the classification result ''su_svm.tif'' to QGIS.
 +
## Right click ''su_svm.tif'' in the [[TOC]] and select {{mitem|text=Properties --> Style --> Style --> Load Style}}.
 +
## Load ''classifcation.qml'', which you should be available in the course data.
 +
## Open the Google Maps Layer under {{mitem|text=Web --> ObenLayers plugin --> Add Google Satellite layer}} and look for misclassification.
 +
 
 +
=== Compute a Confusion matrix with independent reference data ===
 +
# Open {{mitem|text=Orfeo Toolbox --> ComputeConfusionMatrix (Vector)}} (see figure '''D''').
 +
# Set ''SUB_LC81950242013188LGN00_MUL.tif'' as {{button|text=Input image}}.
 +
# Set ''train_systematic_seg.shp'' as {{button|text=Input reference vector data}}.
 +
# Set {{button|text=Field name}} to ''C_ID''.
 +
 
 +
 
 +
 
 +
 
 +
=== Figures ===
 +
{|class="wikitable" style="border:0pt"
 +
|style="border:0pt"|[[Image:ComputeImage.png|thumb|450px|'''Figure A''': Dialogues of the ''Compute images second order statistics'']]
 +
|style="border:0pt"|[[Image:TrainImageClassifier.png|thumb|450px|'''Figure B''': Dialogues of the ''TrainImageClassifier (libsvm)'']]
 +
|-
 +
|style="border:0pt"|[[Image:ImageClassification.png|thumb|450px|'''Figure C''': Dialogues of the ''Image Classification'']]
 +
|style="border:0pt"|[[Image:ComputeConfusionMatrix.png|thumb|450px|'''Figure D''': Dialogues of the ''ComputeConfusionMatrix (Vector)'']]
 +
|}
 +
 
 +
 
 +
 
 +
 
 +
== Classification with Semi-Automatic Classification Plugin ==
 +
=== Plugin installation and testing ===  
 
# Installing the plugin.
 
# Installing the plugin.
 
## Click {{button|text=Manage and install plugins}}.
 
## Click {{button|text=Manage and install plugins}}.
Line 13: Line 68:
 
## In the appearing menu, select the {{button|text=Settings}} tab (figure '''B'''). Click {{button|text=Test Grass GIS}} and wait until the message {{button|text=Test OK}} appears. Do the same the Orfeo Toolbox, Saga and Qgis geoalgorithms.
 
## In the appearing menu, select the {{button|text=Settings}} tab (figure '''B'''). Click {{button|text=Test Grass GIS}} and wait until the message {{button|text=Test OK}} appears. Do the same the Orfeo Toolbox, Saga and Qgis geoalgorithms.
  
== Classification ==
+
=== Classification ===
 
# Add the raster map ''188_pca_indices.tif'' from the [[course data]] (see previous exercises).
 
# Add the raster map ''188_pca_indices.tif'' from the [[course data]] (see previous exercises).
 
# Also add the vector layer ''Training_manual_poly.shp''.
 
# Also add the vector layer ''Training_manual_poly.shp''.
  
=== ROI digitalization ===
+
==== ROI digitalization ====
 
For better understanding of the workflow, try digitizing some  
 
For better understanding of the workflow, try digitizing some  
 
'''R'''egions '''O'''f '''I'''nterest yourself.  
 
'''R'''egions '''O'''f '''I'''nterest yourself.  
Line 35: Line 90:
 
# After having added a few classe, select {{button|text=Minimum distance}} in the {{button|text=Classification algorithm}} section. Click {{button|text=+}} in the {{button|text=Classification preview}} section. By clicking somewhere on the map, a small preview for a section of the map will be generated.
 
# After having added a few classe, select {{button|text=Minimum distance}} in the {{button|text=Classification algorithm}} section. Click {{button|text=+}} in the {{button|text=Classification preview}} section. By clicking somewhere on the map, a small preview for a section of the map will be generated.
  
=== Using predefined ROIs ===
+
==== Using predefined ROIs ====
 
Just adding a few classes will not generate a satisfying classification result. For a high quality classification, ROIs have to be very well defined, which requires a lot of time. For a supervised classification closer to real-life, you can use some predefined ROIs.
 
Just adding a few classes will not generate a satisfying classification result. For a high quality classification, ROIs have to be very well defined, which requires a lot of time. For a supervised classification closer to real-life, you can use some predefined ROIs.
 
# Load the shapefile ''training_manual_poly.shp'' into the project and select it as training shapefile. You'll see how the ROI list is automatically updated.
 
# Load the shapefile ''training_manual_poly.shp'' into the project and select it as training shapefile. You'll see how the ROI list is automatically updated.
Line 42: Line 97:
 
# Click {{button|text=Perform classification}}. Enter name and path for the output map (e.g. ''ml_classification.tif'') and wait for the classification to finish (figure '''C'''). This may take a long time! Plan to do some different work (or just have lunch) while the algorithm is running.
 
# Click {{button|text=Perform classification}}. Enter name and path for the output map (e.g. ''ml_classification.tif'') and wait for the classification to finish (figure '''C'''). This may take a long time! Plan to do some different work (or just have lunch) while the algorithm is running.
  
=== Alternative algorithms and accuracy assessment ===
+
==== Alternative algorithms and accuracy assessment ====
 
To get an impression of results depending on the alorithm selected, try the {{button|text=Maximum likelihood}} classifier as {{button|text=Classification algorithm}}.  
 
To get an impression of results depending on the alorithm selected, try the {{button|text=Maximum likelihood}} classifier as {{button|text=Classification algorithm}}.  
 
In the {{button|text=Semi Automatic classification}} dialogue (figure '''D'''), select the {{button|text=Post processing}} tab to view the error matrix. If desired, it can be saved for future reference.
 
In the {{button|text=Semi Automatic classification}} dialogue (figure '''D'''), select the {{button|text=Post processing}} tab to view the error matrix. If desired, it can be saved for future reference.
Line 49: Line 104:
  
  
==Figures==
+
=== Figures ===
 
{| class="wikitable" style="border:0pt"
 
{| class="wikitable" style="border:0pt"
 
|style="border:0pt"|[[Image:RemSens_Exercise08_02.png|thumb|450px|'''Figure A''': Dialogues of the ''Semi-Automatic Classification Plugin]]
 
|style="border:0pt"|[[Image:RemSens_Exercise08_02.png|thumb|450px|'''Figure A''': Dialogues of the ''Semi-Automatic Classification Plugin]]

Revision as of 12:07, 18 January 2016

Construction.png sorry: 

This section is still under construction! This article was last modified on 01/18/2016. If you have comments please use the Discussion page or contribute to the article!

In this article, you will learn how to conduct a supervised image classification in QGIS

Contents

Classification with Orfeo Toolbox

Zonal Statistics

  1. Add the LandSat-8 imagery SUB_LC81950242013188LGN00_MUL.tif into a QGIS project. It should be available in the course data.
  2. Calculate mean and standard error for each band of the LandSat-8 imagery.
    1. Open Orfeo Toolbox --> Compute images second order statistics (see figure A).
    2. Set SUB_LC81950242013188LGN00_MUL.tif as Input images.
    3. Save the Output XML file as SUB_LC81950242013188LGN00_mul.tif.xml.

Train image classifier

  1. Add the training areas training_manual_poly.shp into QGIS. It should be available in the course data.
  2. Open Orfeo Toolbox --> TrainImageClassifier (libsvm) to use the Support Vector Machine SVM algorithm (see figure B).
  3. Set SUB_LC81950242013188LGN00_MUL.tif as Input image list.
  4. Set training_manual_poly.shp as Input vector list.
  5. Set SUB_LC81950242013188LGN00_mul.tif.xml as Input XML image statistics file.
  6. Set Name of discrimination field to C_ID (C_ID refers to the column that contain the LUC classes code).
  7. Save the Output confusion matrix as ConfusionMatrixSVM.csv.
  8. Save the Output model as SVM.model.
  9. Calculation of accuracies :
    Open ConfusionMatrixSVM.csv in LibreOffice or MS Excel and calculate overall, producer’s and user’s accuracies.

Classification of the LandSat-8 imagery

  1. Add the cloud mask cloud_shadow_mask.tif into QGIS. It should be available in the course data.
  2. Open Orfeo Toolbox --> Image Classification (see figure C).
  3. Set SUB_LC81950242013188LGN00_MUL.tif as Input image.
  4. Set cloud_shadow_mask.tif as Input mask.
  5. Set SVM.model as Model file.
  6. Set SUB_LC81950242013188LGN00_MUL.tif.xml as Statistical file.
  7. Save the Output image as su_svm.tif.
  8. Evaluate classification results.
    1. Add the classification result su_svm.tif to QGIS.
    2. Right click su_svm.tif in the TOC and select Properties --> Style --> Style --> Load Style.
    3. Load classifcation.qml, which you should be available in the course data.
    4. Open the Google Maps Layer under Web --> ObenLayers plugin --> Add Google Satellite layer and look for misclassification.

Compute a Confusion matrix with independent reference data

  1. Open Orfeo Toolbox --> ComputeConfusionMatrix (Vector) (see figure D).
  2. Set SUB_LC81950242013188LGN00_MUL.tif as Input image.
  3. Set train_systematic_seg.shp as Input reference vector data.
  4. Set Field name to C_ID.



Figures

Figure A: Dialogues of the Compute images second order statistics
Figure B: Dialogues of the TrainImageClassifier (libsvm)
Figure C: Dialogues of the Image Classification
Figure D: Dialogues of the ComputeConfusionMatrix (Vector)



Classification with Semi-Automatic Classification Plugin

Plugin installation and testing

  1. Installing the plugin.
    1. Click Manage and install plugins.
    2. In the appearing menu, select Add more.
    3. Browse for the Semi-Automatic Classification Plugin (it's most comfortable to use the search-field).
    4. Click Install. If installation was successful, two additional windows should add to the QGIS GUI (Classification and ROI creation, see figure A).
  2. Testing the plugin
    1. For the plugin to work, you need to make sure that your installations of GRASS GIS, ORFEO Toolbox and SAGA GIS work correctly.
    2. With the plugin installed, select Raster --> Semi Automatic Class Plugin.
    3. In the appearing menu, select the Settings tab (figure B). Click Test Grass GIS and wait until the message Test OK appears. Do the same the Orfeo Toolbox, Saga and Qgis geoalgorithms.

Classification

  1. Add the raster map 188_pca_indices.tif from the course data (see previous exercises).
  2. Also add the vector layer Training_manual_poly.shp.

ROI digitalization

For better understanding of the workflow, try digitizing some Regions Of Interest yourself.

  1. First, you need to create a new shapefile to store the ROIs.
    • In the Input section of the ROI creation menu, click the New shapefile button. Just select the directory and file for the new shapefile and add it to the canvas. Click the Refresh list of shapefiles button and select your shapefile from the pulldown menu.
  2. In the ROI Definition section you can add define the attributes of each ROI. The Macroclass ID, which may be used to code sub-classes of the main classes (like e.g. Coniferous forest as a macroclass of Forest), the Class ID and the name of the class in the Information column.
  3. As an example, enter Urban area in the Information column and leave the ID's as they are.
  4. Looking at the ROI creation section, you see two options for generating the ROI:
    • By clicking +, you can select nondimensional points at the map. Simply place them in pixel clusters you have identified as belonging to the respective class. The regions will later be generated by region growing.
    • A more precise way is to delineate ROI polygons using the Create a ROI polygon tool. You can re-draw the shape of a specific pixel cluster on the map and finish with a right-click.
  5. After having digitized a certain number of points or polygons for a ROI, click Save ROI. Wait until the computation is finished. You will then see the ROI being added to the ROI list in the Classification window.
  6. Repeat ROI generation for a few classes, like e.g.
    • Forest
    • Agricultural area
    • Water
    • Clouds
  7. After having added a few classe, select Minimum distance in the Classification algorithm section. Click + in the Classification preview section. By clicking somewhere on the map, a small preview for a section of the map will be generated.

Using predefined ROIs

Just adding a few classes will not generate a satisfying classification result. For a high quality classification, ROIs have to be very well defined, which requires a lot of time. For a supervised classification closer to real-life, you can use some predefined ROIs.

  1. Load the shapefile training_manual_poly.shp into the project and select it as training shapefile. You'll see how the ROI list is automatically updated.
  2. For Classification style click Select qml and browse for the file classification.qml from the course data.
  3. In the Classification output section, check the Classificatin report and Calculate accuracy boxes.
  4. Click Perform classification. Enter name and path for the output map (e.g. ml_classification.tif) and wait for the classification to finish (figure C). This may take a long time! Plan to do some different work (or just have lunch) while the algorithm is running.

Alternative algorithms and accuracy assessment

To get an impression of results depending on the alorithm selected, try the Maximum likelihood classifier as Classification algorithm. In the Semi Automatic classification dialogue (figure D), select the Post processing tab to view the error matrix. If desired, it can be saved for future reference.



Figures

Figure A: Dialogues of the Semi-Automatic Classification Plugin
Figure B: The Semi-Automatic Classification Plugin menu
Figure C: The classified landcover map
Figure D: The Accuracy menu with error matrix
Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export