Object-based classification (Tutorial)

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Object-based classifcation using SVM algorithm)
Line 34: Line 34:
 
== Object-based classifcation using SVM algorithm ==
 
== 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.
 
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
+
Start --> All Programs --> OSGeo4W --> OSGeo4W Shell or double click on the file
 
'C:\OSGeo4W64\OSGeo4W.bat'. A windows command shell opens. Type  
 
'C:\OSGeo4W64\OSGeo4W.bat'. A windows command shell opens. Type  
  

Revision as of 19:42, 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. Type


info.png Info
For more detailed information on the SVM algorithm visit the library website
  1. Load the raster map 188_pca_indices_pan.tif provided in the course data. Open Mean Shift Segmentation (Large scale, vector output) from the Orfeo toolbox algorithms in the Processing bar.
  2. Select 188_pca_indices_pan.tif as input image. Change Range radius to 0.5 and Min Region size to 50. Specify the output file as Segments_all.shp and click RUN.
  3. 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 Properties --> Style and select Fill-Simple fill with No brush as Fill style. Change the border outline colour to white for better visibility (see figure C).
  4. 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 Split image tool from the Orfeo toolbox. Select Image manipulation --> Split image and specify output image.
  5. To extract pixel spectral data for each object using the Zonal statistics Plugin: Install Zonal Statistics Plugin from the Plugins --> Manage and Install plugins menu. Select Get more and browse for the Zonal statistics plugin. After successfully installing the tool, open it from 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.
  6. Rasterize the segments to prepare for classification: Open the Rasterization tool from the Orfeo tool box, selecting Vector Data Manipulation --> Rasterization. Select Segments_all.shp as Input vector dataset. Select 188_pca_indices_pan_mean.tif as Input reference image. Also enter the input coordinates Output Upper-left x and Output Upper-left y. The coordinates can be found in the Metadata tab of the layer Properties. Change Spacing (GSD)x and Spacing (GSD)y spacing to 15 and Rasterization mode to attribute. Specify the output file and click RUN.
  7. 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 Vector --> Research Tools --> Random selection. Set Number of Features to 210. Press OK. Right click the layer Segment_all.shp and Save selected objects as 210_selected.shp. Load the new shapefile into QGIS.
  8. Specify the class for each object in 210_selected.shp file according to table A Where do I find this? - Levent (talk). This is the training dataset for maximum likelihood classification. Load a Google Maps Image from the OpenLayers plugin: Plugins --> OpenLayers plugin --> Add Google Satellite layer. Install the QuickMultiAttributeEdit plugin. The tool simply helps in editing attributes of a vector file without opening the attribute table. Open the tool from 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 Zoom map to the selected row, identify the land use type by corroborating with google imagery. Press F12 key to open the QuickMultiAttributeEdit and set the IDClass corresponding to the Class Code in Table A. Repeat this procedure for each segment.
  9. Perform maximum likelihood classification of the object segments using the Semiautomatic classification plugin: To open the plugin go to Raster --> Semi-Automatic Classification Plugin --> Semi-Automatic Classification Plugin. Click Show docks. In the Semi-Automatic:ROI creation window select input as 188_pca_indices_ pan_mean.tif., Select a training shapefile as train_segments_6class.shp. Leave the ROI parameters to default. In the Semi-Automatic: Classification window select classification algorithm to Maximum Likelihood, select qml as classification.qml. Check Create vector, Apply mask, Classification report and Calculate accuracy. Specify a cloud mask as cloud_mask.shp. Click 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 Post processing tab and select Accuracy in the Semi-Automatic Classification Plugin window. Load semi_automatic_classification.tif in Select the classification to assess and train_segments_6class.shp in Select the reference shapefile and click Calculate error matrix (see figure E). We did all of this in ecercise 08. Shouldn't we just link there? - Levent (talk)
Figure C: Result of segmentation by mean shift clustering with the Orfeo Toolbox Mean Shift Segmentation algorithm
Figure D: Result of the semi-automatic maximum likelihood classification
Figure D: Error matrix for the semi-automatic maximum likelihood classification

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