Oft-stat

From Open Foris Wiki

Jump to: navigation, search

Extracts image statistics into a text file, based on zone/segment level

Usage: oft-stat -i <infile> -o <outfile> [-um maskfile] [-mm] [-noavg] [-nostd] [-h help]

  • Computes image statistics at zone/segment level and outputs a text file.
  • You need to give at least the input image file (-i option) and the output file (-o). The output file should be a text file (.txt).
  • Normally, you give also a maskfile (-um maskfile) which is an image consisting of pixels with integer values:
    • Pixels having value 0 are not processed.
    • For all other mask values the statistics are reported separately.
    • When the -um option is not used, statistics are a summary of all pixels in the image
  • The output format in the text file is: ID #pixels avgband1 ...avgbandN stdband1 ...stdbandN
  • If -mm option is given, output format in the text file is: ID #pixels minband1 ... minbandN maxband1 ...maxbandN avgband1 ...avgbandN stdband1 ...stdbandN

Options:

-noavg = program does not compute the averages
-nostd = program does not compute the std's
-mm = program computes and prints out also minimum and maximum
-h = prints out help
  • NOTE: for benefit of users running scripts using the older version based on order of data files instead of options -i, -o and -um, the program can still be used that way


Example:

oft-stat -i images/input.tif -o results/stats.txt -um images/segments.tif


Example:

  • Get Example data set
  • For this exercise following tools are used: oft-stat
  • Open your working directory using
cd /home/...

1. Now we run oft-stat with input: images/landsat-t1.tif, output: results/stats.txt:

oft-stat -i images/landsat_t1.tif -o results/stats.txt

2. Print the output in terminal:

less results/stats.txt
 1 10500000 48.742120 21.032891 19.848100 41.126436 50.192329 126.019212 21.810292 3.532883 2.776924 5.170575 6.554972 13.140675 2.275625 8.220984

Explanation of values for each column:

  • Col1: ID (in this case one as no mask file has been given)
  • Col2: Number of pixels
  • Col3: Average value of band1
  • Col4 - col9: Average value of band2 - band7
  • Col10 - col16: Standard deviation of band1 - band7

3. Now we run oft-stat with input: images/landsat-t1.tif, output: results/stats_mm.txt, and the option -mm to produce also minimum and maximum values:

oft-stat -i images/landsat_t1.tif -o results/stats_mm.txt -mm

4. Print the output in terminal:

less results/stats_mm.txt
 1 10500000 20.000000 1.000000 1.000000 8.000000 5.000000 112.000000 1.000000 255.000000 255.000000 208.000000 255.000000 255.000000 195.000000 255.000000 48.742120 21.032891 19.848100 41.126436 50.192329 126.019212 21.810292 3.532883 2.776924 5.170575 6.554972 13.140675 2.275625 8.220984

Explanation of values for each column:

  • Col1: ID (in this case one as no mask file has been given)
  • Col2: Number of pixels
  • Col3: Minimum value of band1
  • Col4 - col9: Minimum value of band2 - band7
  • Col10 - col16: Maximum value of band1 - band7
  • Col17 - col23: Average value of band1 - band7
  • Col24 - col30: Standard deviation of band1 - band7

5. Now we run oft-stat with input: images/landsat-t1.tif, output: results/stats_mask.txt; optional mask: images/segments.tif:

oft-stat -i images/landsat-t1.tif -o results/stats_mask.txt -um images/segments.tif 

6. Print the first 10 lines of the output in terminal:

head results/stats_mask.txt
 49 60 49.183333 20.366667 18.883333 36.800000 47.866667 126.500000 20.700000 0.929583 0.551321 0.640224 1.054450 1.890804 0.504219 1.046382 
 89 56 47.714286 20.053571 18.428571 37.125000 49.035714 125.571429 20.660714 1.073893 0.553325 0.598700 1.280092 1.747354 0.499350 0.977507 
 26 132 49.310606 20.295455 18.651515 35.840909 46.863636 126.833333 20.257576 0.989507 0.490188 0.552370 0.799136 1.763812 0.481199 1.088603 
 220 54 51.203704 22.629630 23.666667 38.592593 58.777778 131.370370 28.685185 2.870669 2.139444 4.374023 2.375333 9.681078 0.957518 6.804061 
 231 132 56.416667 27.325758 34.606061 43.409091 82.636364 134.871212 45.454545 1.644058 1.207459 2.153490 1.689458 4.386434 2.786021 3.416090 
 236 55 46.200000 19.272727 16.290909 41.963636 39.927273 124.654545 15.000000 1.145038 0.449467 0.533081 0.961550 0.939948 0.479899 0.769800 
 7 53 48.886792 20.056604 18.339623 37.207547 45.698113 125.698113 19.396226 1.049915 0.534037 0.586495 0.947841 1.169893 0.463470 0.967543 
 52 105 49.580952 20.866667 19.666667 38.161905 53.990476 126.361905 22.847619 0.988209 0.555855 0.780368 0.951960 2.100802 0.482856 1.089998 
 114 51 46.960784 19.470588 16.235294 41.294118 37.725490 124.764706 15.039216 0.937247 0.542326 0.789639 0.807319 1.201306 0.428403 0.847603 
 138 55 45.690909 19.272727 16.054545 40.672727 40.036364 123.563636 14.909091 1.051854 0.449467 0.890655 1.155575 1.439697 0.739460 0.866511

The output is basically the same as in step 4. However, now average and standard deviation are not given for the whole image, but for each zone/segment value of the mask file (exception: value 0 that is not processed).

Explanation of values for each column:

  • Col1: ID (in this case one as no mask file has been given)
  • Col2: Number of pixels
  • Col3: Average value of band1
  • Col4 - col9: Average value of band2 - band7
  • Col10 - col16: Standard deviation of band1 - band7

7. Depending on the purpose, you can now try the different options:

  • -mm if you want to compute minimum and maximum values as well
  • -noavg if you do not want to output the average
  • -nostd if you do not want to compute the standard deviation.

The output will always be in the following order:

ID, number of pixels, [minimum if -mm is chosen], [maximum if -mm is chosen], average, standard deviation.

If the input image has several bands, the parameters are given for all bands.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools