Oft-kmeans

From Open Foris Wiki

Jump to: navigation, search

oft-kmeans carries out unsupervised classification with k-means algorithm.

Usage: oft-kmeans -i <infile> -o <output_image> [OPTIONS]

Options:

-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64}
-um <maskfile>
-auto automated division of data
-aw <ask weights for input bands>
-h print more help

By default, the program asks user to input two parameters:

  1. input text file
  2. number of classes
  • The input text file is a collection of signatures from the input file.
    • It contains at minimum the greyvalues of each band
    • It can be done with oft-gengrid.bash and oft-extr
    • The program uses it to establish the cluster centres and proceeds by assigning each pixel the Class ID of the closest cluster centre.
    • The proximity of the cluster centres is computed using Euclidean distance in the spectral feature space.
  • If the -auto option is used, the program divides the data automatically and the number of clusters is not requested.
  • If the -aw option is used, the programs asks user to provide weight for each of the input bands.
  • NOTE: for benefit of users running scripts using the older version based on order of files instead of option -i, the program can still be used that way


Exercise:

cd /home/...
  • The exercise is divided into two step: first we prepare the input signature text file which is need for oft-kmeans, then we will run the classification tool itself:


1. Creation of input signature text file

  • We want to generate a grid of points over our image landsat_t1.tif using oft-gengrid.bash with user-defined spacing in x and y directions, in this case 5000 x 5000 m distance between the points in X and Y directions. The output file gengrid.txt contains information on the created grid: ID x y
oft-gengrid.bash landsat_t1.tif 5000 5000 gengrid.txt
head gengrid.txt
1 730785 -2456134
2 730785 -2451134
3 730785 -2446134
4 730785 -2441134
5 730785 -2436134
6 730785 -2431134
7 730785 -2426134
8 730785 -2421134
9 730785 -2416134
10 730785 -2411134
  • To extract the values from our input image landsat_t1.tif for those pixels that lay on our grid we created in the previous step we run oft-extr. Output: my_extr.txt
oft-extr -o my_extr.txt gengrid.txt  landsat_t1.tif
head my_extr.txt
 1.00   730785.00 -2456134.00   50.00    3441.00   52.00      24.00      24.00      51.00      65.00     128.00      29.00 
 2.00   730785.00 -2451134.00   50.00    3274.00   47.00      19.00      18.00      37.00      47.00     124.00      20.00 
 3.00   730785.00 -2446134.00   50.00    3108.00   52.00      23.00      22.00      53.00      57.00     127.00      26.00 
 4.00   730785.00 -2441134.00   50.00    2941.00   49.00      20.00      17.00      34.00      43.00     124.00      19.00 
 5.00   730785.00 -2436134.00   50.00    2774.00   47.00      20.00      18.00      34.00      44.00     125.00      19.00 
 6.00   730785.00 -2431134.00   50.00    2608.00   51.00      21.00      20.00      36.00      51.00     128.00      23.00 
 7.00   730785.00 -2426134.00   50.00    2441.00   62.00      29.00      38.00      53.00      85.00     136.00      45.00 
 8.00   730785.00 -2421134.00   50.00    2274.00   48.00      21.00      18.00      34.00      45.00     126.00      19.00 
 9.00   730785.00 -2416134.00   50.00    2108.00   49.00      20.00      19.00      35.00      47.00     125.00      20.00 
 10.00  730785.00 -2411134.00   50.00    1941.00   49.00      20.00      18.00      35.00      45.00     125.00      18.00 

2. Unsupervised classification - oft-kmeans

  • Now we run oft-kmeans with

Input: landsat_t1.tif

Output: my_kmeans.tif

oft-kmeans -o my_kmeans.tif -i landsat_t1.tif
The program will ask you for:
Input signature file name?: my_extr.txt   
Number of clusters?: 25                   //For this example we choose 25 clusters
  • Load your result my_kmeans.tif in QGIS:

You can see the classified image my_kmeans.tif with pixel values between 1 and 25.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools