Unsupervised Classification and Segmentation in the Feature Space

From Open Foris Wiki

Jump to: navigation, search

This exercise provides an example of unsupervised classification at pixel level of a subset of Landsat Image. Adjacent pixels of the same cluster are then grouped into objects.

NOTE: An exercise with a provided data set and screen shots can be found under oft-cluster.bash.

To go through this exercise, please follow the following steps:

Example: cluster.bash LT51650672009351JSA00_stack.img 50classes10percent.img 50 0.1 mask_LT51650672009351JSA00.img

This example will create an output image (50classes10percent.img) were every pixel has been assigned a class from 0 to 50 except the pixels of value 0 in the mask image.

NOTE: if you're using LEDAPS input, you can generate the mask using trim_ledaps.bash


1.Get Example data set

2. Open your working directory using

cd /home/...

In this exercise we will combine two tools and a gdal command that can be used together: oft-cluster.bash, oft-clump and gdal_polygonize.py to compute clusters and convert them into polygons.

EXERCISE with data set

1. oft-cluster.bash

  • Lets run oft-cluster.bash with Input: landsat_t1.tif; Output: cluster50.tif for 50 classes and 10 percent
Note: it takes some time computing, so be patient.
oft-cluster.bash landsat_t1.tif cluster50.tif 50 0.1
  • Load the result in QGIS and see that all the pixel values are between 1 and 50 corresponding to the 50 classes we defined in the command line.

2. oft-clump

  • Now we will run oft-clump. This tool is meant for separating uniform regions in a class image. Get detailed information under oft-clump:

Input: cluster50.tif

Output: clump_clus50.tif

oft-clump cluster50.tif clump_clus50.tif

3. gdal_polygonize

  • In the last step we want to create polygons using the

Input: clump_clus50.tif

Output: clump_clus50.shp

gdal_polygonize.py clump_clus50.tif -f "ESRI Shapefile" clump_clus50.shp
Zoom into the cluster image Cluster50.tif Corresponding zoom into the shapefile clump_clus50.shp.

EXERCISE with data to be downloaded from GloVis

  1. Download your Landsat scene using e.g. GloVis
  2. Cut a subset of the input image for the classification
    gdal_translate -srcwin 4000 4000 500 500 landsat.tif subset.tif

The gdal_translate utility can be used to cut a subwindow from the input image using the srcwin option -srcwin xoff yoff xsize ysize <infile> <outfile>

xoff, yoff: x,y coordinates of the upper left corner of the subset (column, row)

xsize, ysize: size of subset in pixels

  1. Decide appropriate sampling density and number of clusters and run the
    oft-cluster.bash subset.tif cluster50.tif 50 10
    Here, the last two parameters are number of clusters and the sampling density in %. For more details, please have a look at cluster.bash or oft-kmeans
  2. Now, you can convert your clustering output into a segmentation by labelling the connected components
    oft-clump cluster50.tif clump_clus50.tif
  3. Finally, you can vectorize the segments and visualize the results with OpenEV, QGIS or similar software.
    gdal_polygonize.py clump_clus50.tif -f "ESRI Shapefile" clump_clus50.shp

Back to Open Foris Toolkit Main Page

Back to Tools & Exercises

Personal tools