Image classification is one of the most complex aspects of remote sensing. While QGIS is able to color pixels based on values for visualization, it stops short of doing much classification. It does provide a Raster Calculator tool where you can perform arbitrary math formulas on an image, however it does not attempt to implement any common algorithms. The Orfeo Toolbox is dedicated purely to remote sensing and includes an automated classification algorithm called K-means clustering, which groups pixels into an arbitrary number of similar classes to create a new image. We can do a nice demonstration of image classification using this algorithm.
For this recipe, we will use a false color image which you can download here:
https://geospatialpython.googlecode.com/files/FalseColor.zip
Unzip this TIFF file and place it in your /qgis_data/rasters
directory.
All we need to do is run the algorithm on our input image. The important parameters are the second, third, sixth, and tenth parameters. They define the input image name, the amount of RAM to dedicate to the task, the number of classes, and the output name respectively.
processing
module in the QGIS Python Console:import processing
otb
algorithm using the processing.runandload()
method to display the output in QGIS:processing.runandload("otb:unsupervisedkmeansimageclassification","/qgis_data/rasters/FalseColor.tif",768,None,10000,3,1000,0.95,"/qgis_data/rasters/classify.tif",None)
Keeping the class number low allows the automated classification algorithm to focus on the major features in the image and helps when us to achieve a very high level of accuracy determining overall land use. Additional automated classification would require supervised analysis with training data sets and more in-depth preparation. But the overall concept would remain the same. QGIS has a nice plugin for semi-automatic classification. You can learn more about it at the following URL:
https://plugins.qgis.org/plugins/SemiAutomaticClassificationPlugin/