Oft-cluster.bash

From Open Foris Wiki

Jump to: navigation, search

oft-cluster.bash clusters raster images using oft-gengrid.bash, oft-extr and oft-kmeans

Usage: oft-cluster.bash <input.img> <output.img> <nbr_clusters> <sampling_density%> [mask]

oft-cluster.bash clusters input image into a given number of clusters. The clustering process is as follows:

  1. generate a systematic sample using the given sample density and covering the area of input.img. For more details, please have a look at oft-gengrid.bash
  2. extract spectral (or other) information for every point of the grid using oft-extr
  3. cluster the grid points into given number of clusters using k-means algorithm oft-kmeans
  4. classify each image pixel in one of the generated clusters using NN classification with Euclidean distance in the feature space

The mask values are:

  • 0 = do not classify
  • 1 = classify

Example:

cluster.bash LT51650672009351JSA00_stack.img 50classes10percent.img 50 10 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


Exercise:

cd /home/...


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 andsat_t1.tif cluster50.tif 50 10
  • 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.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools