Unit 28 - Classification

Imagery data in GRASS GIS can be grouped (e.g. channel-wise) by i.group module (Imagery ‣ Develop images and groups ‣ Create/edit group). Groups and subgroups allows user to perform analysis on any combination of the raster maps in a group. Group or subgroup is taken as input for most of GRASS imagery modules (i.*).

../_images/i-group-0.png

Fig. 128 Creating imagery group from the GUI.

Note

When running command from Bash, the input maps can be defined by g.list output.

i.group group=L2A_T32VNM_20170523T104031 subgroup=L2A_T32VNM_20170523T104031 \
input=`g.list rast pattern=L2A_T32VNM_20170523T104031_B* sep=comma`

Tip

The first step as pre-analysis for a subsequent classification could be r.smooth.seg to produces a smooth approximation of the data and performs discontinuity detection.

Tip

In case of panchromatic maps or limited amount of channels, it is often recommended to generate synthetic channels through texture analysis r.texture.

Segmentation

Identification of segments (objects) from imagery data can be perform by i.segment.

i.segment group=L2A_T32VNM_20170523T104031 output=L2A_T32VNM_20170523T104031_seg_04 threshold=0.4 memory=1000
../_images/segment.png

Fig. 129 Segmentation output on the left, RGB composition on the right.

Unsupervised classification

Unsupervised classification can be done using two GRASS GIS modules, i.cluster and i.maxlik.

i.cluster generates spectral signatures for land cover types in an image using a clustering algorithm. The resulting signature file is used as input for i.maxlik, to generate an unsupervised image classification.

i.cluster group=L2A_T32VNM_20170523T104031 subgroup=L2A_T32VNM_20170523T104031 \
signaturefile=cluster classes=3 reportfile=geodata/class_cluster.txt

i.maxlik group=L2A_T32VNM_20170523T104031 subgroup=L2A_T32VNM_20170523T104031 \
signaturefile=cluster output=L2A_T32VNM_20170523T104031_cluster
../_images/cluster.png

Fig. 130 Unsupervised classification output.

Supervised classification

The first step in supervised classification is to define training areas. For this task GRASS GIS offers specialized tool called g.gui.iclass. Alternatively also more generic vector digitizer g.gui.vdigit can be used as shown below.

../_images/vdigit.png

Fig. 131 Vector digitizer for defining training areas.

By vector digitizer a new vector map T32VNM_20170523T104031_training can be created with following attribute columns:

  • class varchar with 5 characters, for class name
  • class_i integer, for class id
  • color varchar with 11 characters, for color representation

A new area can be created from vector digitizer toolbar grass-polygon-create Digitize new area.

It is enough for each training area to define class id class_i. The rest of attributes (class and color) can be defined afterwards by Attribute Data Manager.

Tip

Instead of Attribute Data Manager also db.execute can be used to fill attribute columns. See example below which shows how to update columns class and color based on specified class_i attribute.

db.execute sql="UPDATE T32VNM_20170523T104031_training set class_i=1 where class='water'"
db.execute sql="UPDATE T32VNM_20170523T104031_training set class_i=2 where class='arti'"
db.execute sql="UPDATE T32VNM_20170523T104031_training set class_i=3 where class='vege'"

db.execute sql="UPDATE T32VNM_20170523T104031_training set color='35:167:234' where class='water'"
db.execute sql="UPDATE T32VNM_20170523T104031_training set color='102:102:102' where class='arti'"
db.execute sql="UPDATE T32VNM_20170523T104031_training set color='65:232:70' where class='vege'"
../_images/training_attributes.png

Fig. 132 The attribute table of training vector map.

At this point vector map with training areas is converted to raster format. This operation can be done in GRASS by v.to.rast.

v.to.rast input=T32VNM_20170523T104031_training output=T32VNM_20170523T104031_training \
type=area use=attr attribute_column=class_i label_column=class rgb_column=color
../_images/trainings.png

Fig. 133 The training areas as raster map (RGB composition on background).

The second step means to run classfier. There are different classifiers based on:

  • radiometric method,
  • radiometric and geometric method, or
  • machine learning

Radiometric method can be performed in GRASS GIS using i.gensig to generate statistics to be used by i.maxlik, see example below.

i.gensig training=T32VNM_20170523T104031_training group=L2A_T32VNM_20170523T104031 \
subgroup=L2A_T32VNM_20170523T104031 signaturefile=gensig_nosegment

i.maxlik group=L2A_T32VNM_20170523T104031 subgroup=L2A_T32VNM_20170523T104031 \
signaturefile=gensig_nosegment output=L2A_T32VNM_20170523T104031_maxlik

In radiometric and geometric method statistics is generated by i.gensigset together with i.smap which performs contextual image classification using sequential maximum a posteriori (SMAP) estimation.

i.gensigset training=T32VNM_20170523T104031_training group=L2A_T32VNM_20170523T104031 \
subgroup=L2A_T32VNM_20170523T104031 signaturefile=gensigset_nosegment

i.smap group=L2A_T32VNM_20170523T104031 subgroup=L2A_T32VNM_20170523T104031 \
signaturefile=gensigset_nosegment output=L2A_T32VNM_20170523T104031_smap \
goodness=L2A_T32VNM_20170523T104031_smap_good

Machine learning approach can be applied for example by r.learn.ml which represents a front-end to the scikit-learn python package.

Note

r.learn.ml is an add-on so you have to install it through g.extension. Note that r.learn.ml including dependecies is already installed on tailored virtual machine.

r.learn.ml trainingmap=T32VNM_20170523T104031_training \
group=L2A_T32VNM_20170523T104031 output=L2A_T32VNM_20170523T104031_learn
../_images/classification.png

Fig. 134 Different supervised methods. In the left radiometric (i.maxlik) method, in the center radiometric and geometric method (i.smap) and in the right machine learning approach performed by r.ml.learn.

Tip

In order to get better classification output some post-processing steps can be performed.