Oft-segstat

From Open Foris Wiki

Jump to: navigation, search

Extracts segment level shape (size, bounding box, # edge pixels) and spectral (averages and standard deviations) to a text file.

Usage: oft-segstat [-std] [-shape] <maskfile> <infile> <outfile>

This script can also be used after oft-seg.

Example:

oft-segsstat seg.tif input.tif stats.txt

Option:

<maskfile> 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.

The output:

  • The basic usage outputs the following space separated columns:
1 Segment ID
2 Size
3 - (3+n) Segment averages pixel values for all n input image bands
  • -std adds standard deviations for all input bands in the end of each record.
  • -shape changes the output format to follwoing:
1 Segment ID
2 Size
3 # of neighbours
4 xmin
5 xmax
6 ymin
7 ymax
8 # edge pixels
9 - (9 + n) Segment averages pixel values for all n input image bands


Exercise:

  • Get Example data set
  • For this exercise following tools are used: oft-segstat
  • For this exercise we use the Landsat imagery landsat_t1.tif, landuse.shp. Further you need to run oft-seg in a first step to calculated the segmentation file landsat_t1.tif.

2. Open your working directory using

cd /home/...

1. oft-segstat

  • Now we run oft-segstat with Input: landsat_t1.tif, landsat_t1_min50.tif; Output: segstats.txt:
oft-segstat landsat_t1_min50.tif  landsat_t1.tif segstats.txt

The tool will ask you now to define the NoData value which we will set to 0:

Please give NODATA value: 0    //in this step you only need to type the number 0
  • Lets take a look at the first 10 lines of our result segstats.txt:
head segstats.txt
49 60  49.183333 20.366667 18.883333 36.800000 47.866667 126.500000 20.700000
89 56  47.714286 20.053571 18.428571 37.125000 49.035714 125.571429 20.660714
26 132  49.310606 20.295455 18.651515 35.840909 46.863636 126.833333 20.257576
220 54  51.203704 22.629630 23.666667 38.592593 58.777778 131.370370 28.685185
231 132  56.416667 27.325758 34.606061 43.409091 82.636364 134.871212 45.454545
236 55  46.200000 19.272727 16.290909 41.963636 39.927273 124.654545 15.000000
7 53  48.886792 20.056604 18.339623 37.207547 45.698113 125.698113 19.396226
52 105  49.580952 20.866667 19.666667 38.161905 53.990476 126.361905 22.847619
114 51  46.960784 19.470588 16.235294 41.294118 37.725490 124.764706 15.039216
138 55  45.690909 19.272727 16.054545 40.672727 40.036364 123.563636 14.909091

Explanation of the values of each column:

  • Col1: Segment ID
  • Col2: Size
  • Col3 - Coln: Segment average pixel values of band3 - bandn

2. oft-segstat including -std

  • Lets run oft-segstat including the option of adding the standard deviation: Input: landsat_t1.tif, landsat_t1_min50.tif; Output: segstats_std.txt:
oft-segstat -std landsat_t1_min50.tif  landsat_t1.tif segstats_std.txt
  • Again, lets take a look at the first 10 lines of our result segstats_std.txt:
head segstats_std.txt
49 60  49.183333 20.366667 18.883333 36.800000 47.866667 126.500000 20.700000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
89 56  47.714286 20.053571 18.428571 37.125000 49.035714 125.571429 20.660714 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
26 132  49.310606 20.295455 18.651515 35.840909 46.863636 126.833333 20.257576 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
220 54  51.203704 22.629630 23.666667 38.592593 58.777778 131.370370 28.685185 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
231 132  56.416667 27.325758 34.606061 43.409091 82.636364 134.871212 45.454545 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
236 55  46.200000 19.272727 16.290909 41.963636 39.927273 124.654545 15.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
7 53  48.886792 20.056604 18.339623 37.207547 45.698113 125.698113 19.396226 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
52 105  49.580952 20.866667 19.666667 38.161905 53.990476 126.361905 22.847619 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
114 51  46.960784 19.470588 16.235294 41.294118 37.725490 124.764706 15.039216 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
138 55  45.690909 19.272727 16.054545 40.672727 40.036364 123.563636 14.909091 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

Explanation of the values of each column:

  • Col1: Segment ID
  • Col2: Size
  • Col3 - Col9: Segment average pixel values of band3 - band9
  • Col10 - Col16: standard deviation value for each band


3. oft-segstat including option -shape

  • For this exercise we want to create in a first step a mask file that is needed to define which pixels of the satellite image will be included in the calculation. In this case we exclude all pixels that were 0. Input: landsat_t1.tif, Output: landsat_t1_mask.tif:
oft-calc  landsat_t1.tif LT52_CUB00_mask.tif   //create mask same dimension same location
1
#1 0 = 1 0 ?
  • Now we run the segmentation statistic not with the segmentation file we created before using oft-seg, but using a shapefile instead

Input: landuse.shp, landsat_t1_mask.tif, landsat_t1.tif

Output: segstats_shp.txt

oft-segstat -shape landuse  landsat_t1_mask.tif landsat_t1.tif segstats_shp.txt
  • Again, lets take a look at our result segstats_shp.txt:
head segstats_shp.txt
1 10500000 0  0 2999 0 3499 6000 48.742120 21.032891 19.848100 41.126436 50.192329 126.019212 21.810292

Explanation of the values of each column:

  • Col1: Segment ID
  • Col2: Size
  • Col3: # of neighbours
  • Col4: xmin
  • Col5: xmax
  • Col6: ymin
  • Col7: ymax
  • Col8: # edge pixels
  • Col9: Segment average pixel values of band1
  • Col10: Segment average pixel value of band2
  • Coln: Segment average pixels valued of bandn



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools