From Open Foris Wiki
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:
- 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
- extract spectral (or other) information for every point of the grid using oft-extr
- cluster the grid points into given number of clusters using k-means algorithm oft-kmeans
- 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
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
- Get Example data set
- For this exercise following tools are used: oft-cluster.bash, oft-clump, gdal_polygonize to compute clusters and convert them into polygons.
- Open your working directory using
- 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.
- Now we will run oft-clump. This tool is meant for separating uniform regions in a class image. Get detailed information under oft-clump:
oft-clump cluster50.tif clump_clus50.tif
- In the last step we want to create polygons using the
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.|