Object-based classification (Tutorial)

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Object-based classifcation using SVM algorithm)
Line 35: Line 35:
 
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.
 
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.
 
{{mitem|text=Start --> All Programs --> OSGeo4W --> OSGeo4W Shell}} or double click on the file 'C:\OSGeo4W64\OSGeo4W.bat'. A windows command shell opens.  
 
{{mitem|text=Start --> All Programs --> OSGeo4W --> OSGeo4W Shell}} or double click on the file 'C:\OSGeo4W64\OSGeo4W.bat'. A windows command shell opens.  
# Type ''otbgui_ComputOGRLayersFeturesStatistics''
+
# Type ''otbgui_ComputeOGRLayersFeturesStatistics''
 
##* ''Name of the input vector'' is the file {{button|text=seg_188_pca_cmask_8b_train.shp}}.
 
##* ''Name of the input vector'' is the file {{button|text=seg_188_pca_cmask_8b_train.shp}}.
 
##* ''XML file containing mean and variance of each feature'' is {{button|text=seg_188_pca_cmask_8b_train.shp.xml}}.
 
##* ''XML file containing mean and variance of each feature'' is {{button|text=seg_188_pca_cmask_8b_train.shp.xml}}.
Line 41: Line 41:
 
Calcualte also an XML file for vector file {{button|text=seg_188_pca_cmask_8b.shp}}.
 
Calcualte also an XML file for vector file {{button|text=seg_188_pca_cmask_8b.shp}}.
  
 +
# Type ''otbgui_TrainOGRLayersClassifier''
  
 +
# Type ''OGRLayersClassifier''
 
   
 
   
  
Line 47: Line 49:
  
 
{{info|message=Info|text=For more detailed information on the SVM algorithm visit the [http://www.csie.ntu.edu.tw/~cjlin/libsvm/ library website]}}
 
{{info|message=Info|text=For more detailed information on the SVM algorithm visit the [http://www.csie.ntu.edu.tw/~cjlin/libsvm/ library 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.
 
# 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}}.
 
# 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''').
 
# 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.
 
# 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.
 
# 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}}.
 
# 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. 
 
# 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.
 
# 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]])}}
 
 
{|class="wikitable" style="border:0pt"
 
|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]]
 
|style="border:0pt"|[[Image:RemSens_Exercise08_04.png|thumb|450px|'''Figure D''': Result of the semi-automatic maximum likelihood classification]]
 
|-
 
|style="border:0pt"|[[Image:RemSens_Exercise08_05.png|thumb|450px|'''Figure D''': Error matrix for the semi-automatic maximum likelihood classification]]
 
|}
 
  
 
== Alternative supervised classification with Support Vector Machine (SVM) ==
 
== Alternative supervised classification with Support Vector Machine (SVM) ==

Revision as of 21:00, 24 January 2016

Contents

Determining segmentation parameters

Mean-shift segmentation of large size images

  1. 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 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 Input image.
      • 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.
  2. Step. We 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.
      • 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.
  3. Step. We 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 188_pca_cmask_8b 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.
  4. 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.Processing-Orfeo Toolbox (image analysis) --> Segmentation-Exact Large-Scale Mean-Shift segmentation, step 4
      • The Input image is the 188_pca_cmask_8b layer.
      • Segmented image is Output image from step 3.
      • The name of Output GIS vector file is 1seg_188_pca_cmask_8b.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 188_pca_cmask_8b.tif to evaluate the segmentation result.

Preparation of reference data

We 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 train_manual_poly.shp.
      • Output vector seg_188_pca_cmask_8b_train.shp.
      • For the rest of parameters keep default values.OK.

We need to rename the field names of the resulting output vector attribut table avoiding upper capitals and underslash using the Table Manager plugin.

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. Start --> All Programs --> OSGeo4W --> OSGeo4W Shell or double click on the file 'C:\OSGeo4W64\OSGeo4W.bat'. A windows command shell opens.

  1. Type otbgui_ComputeOGRLayersFeturesStatistics
      • Name of the input vector is the file seg_188_pca_cmask_8b_train.shp.
      • XML file containing mean and variance of each feature is seg_188_pca_cmask_8b_train.shp.xml.
      • In the List of features to consider for statistics mark the columns meanB0, meanB1, meanB2.Execute.

Calcualte also an XML file for vector file seg_188_pca_cmask_8b.shp.

  1. Type otbgui_TrainOGRLayersClassifier
  1. Type OGRLayersClassifier



info.png Info
For more detailed information on the SVM algorithm visit the library website

Alternative supervised classification with Support Vector Machine (SVM)

  1. Start Monteverdi.
  2. Open 188_pca_indices_pan_mean.tif and train_segments_7class.shp in Monteverdi via File --> Open dataset.
  3. Go to Learning --> SVM classification (EXPERIMENTAL)
  4. Load 188_pca_indices_pan_mean.tif as Input image and train_segments_7class.shp as Training/validation ROIs and press OK.
  5. Specify the Class key as ID_class and click Train. A classification output is seen Monteverdi.
  6. Click Validate to see classification accuracy and Calculate error matrix. See Figure G.
Supervised classification menu in Monteverdi with error matrix
Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export