Oft-his

From Open Foris Wiki

Jump to: navigation, search

Computes image histogram by segments

Usage: oft-his -i <infile> -o <outfile> [-um maskfile] [-hr/-compact][-maxval val]

Options:

-i = specify input image file
-o = specify output text file
-um = specify mask file
-hr = use human readable output format
-compact = use compact output format
-maxval = give maximum input value
-h = print out more help
  • Extracts histograms for the different bands of an input image to an output text file
  • You need to give at least the input image file -i option and the output file -o
  • Typically, you also give a mask file -um. Each mask value gets own histogram, except 0 which is treated as nodata
  • If no mask file is given, a common histogram is computed for whole image
  • Maximum input value needs to be given to allocate enough memory for the histogram table. If the maxval parameter is not given in the command line, it will be asked. For example, for a 8 Bit Landsat image, the maximum value parameter would be 255.
  • The output format is: mask value, frequency of mask value and number of band. The rest of the columns values are frequencies for each image pixel value.
  • 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 with typical parameter setting:

oft-his -i input.img -o histogram.txt -um mask.img -hr -maxval 255
  • The output file will contain nbr_bands lines for every input mask value. The output format is: mask value, frequency of mask value and number of band; the rest of the columns values are frequencies for each image pixel values. For example, in the following output:
1 657846 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 205 2166 10162 29145 70813 136848 145398 117541 82955 40937 14060 4255 1618 707 345 208 140 103 83 48 42 15 17 13 6 3 2 0 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1. 1 = Mask value
  2. 657846 = Frequency of mask value 1
  3. 1 = Number of band
  4. 0 = frequency of value 0 in input image
  5. 0 = frequency of value 1 in input image
  6. 0 = frequency of value 2 in input image
  7. 0 = frequency of value 3 in input image
  8. .
  9. .
  10. .
  • An alternative output format is provided by the -compact option

1 657846 1 12 1 46 1 47 5 48 205 49 2166 50 10162 51 29145 52 70813 53 136848 54 145398 55 117541 56 82955 57 40937 58 14060 59 4255 60 1618 61 707 62 345 63 208 64 140 65 103 66 83 67 48 68 42 69 15 70 17 71 13 72 6 73 3 74 2 76 3 77 1

  • where first three values are


  1. 1 = Mask value
  2. 657846 = Frequency of mask value 1
  3. 1 = Number of band
  • After that, the output consists of value-frequency pairs. That is, entry

12 1 means that 1 pixel of value 12 was found within the region determined by mask value 1. Accordingly, we can see that also single pixels with values 46 was found and that the number of pixels with value 47 was five.

  • In practical applications, the output needs to be converted into more readable format and usable information. For example, one could be interested in the median Landsat DN value within the mask. When using -hr option to produce the output the median could be computed using awk and the following equation:
awk '{obs_point = ($2 - $4)/2} {if (NR == 1) {for(i=5 ; i< NF ; i++) {sum=sum+$i; if(sum >= obs_point) {print i-4; exit}}}}' his1.txt 

Note: that here we exclude background value (0) from the computation.


Exercise:

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

1. oft-his

  • Lets run a oft-his with Input: landsat_t1.tif, Ouptut: histogram.txt, when asked set the maximum input value to 255:
oft-his  -i landsat_t1.tif -o  histogram.txt
head histogram.txt

Extraction of histogram.txt - output is all in one line:

1 10500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 2 1 1 4 2 3 5 2 5 8 7 5 176 1576 12371 114959 758774 1773981 2035039 1918290 1222961 558651 332962 287434 320286 311067 217529 180595 138396 93221 57114 38722 32169 25924 18311 12510 9783 7020 5022 3874 3116 2294 1647 1193 848 632 408 284 185 163 134 72 73 41 16 11 8 10 4 5 7 10 4 6 2 2 0 2 1 2 3 0 1 2 2 2 1 0 1 0 1 1 1 1 0 1 1 3 1 1 0 1 2 1 0 0 0 2 0 1 2 1 0 1 0 


2. oft-his with option -hr for readability (one line per band)

2.1 Lets run a oft-his with Input: landsat_t1.tif, Ouptut: histogram_hr.txt, again, the maximum input value to 255

oft-his  -i landsat_t1.tif -o  histogram-hr.txt -hr
head histogram-hr.txt
1 10500000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 2 1 1 4 2 3 5 2 5 8 7 5 176 1576 12371 114959 758774 1773981 2035039 1918290 1222961 558651 332962 287434 320286 311067 217529 180595 138396 93221 57114 38722 32169 25924 18311 12510 9783 7020 5022 3874 3116 2294 1647 1193 848 632 408 284 185 163 134 72 73 41 16 11 8 10 4 5 7 10 4 6 2 2 0 2 1 2 3 0 1 2 2 2 1 0 1 0 1 1 1 1 0 1 1 3 1 1 0 1 2 1 0 0 0 2 0 1 2 1 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 2 0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 2

1 10500000 2 0 1 1 0 3 2 0 2 3 2 3 0 3 3 2 26 646 8742 191086 2508329 4562947 718031 338584 429870 487321 333295 255746 231077 161926 99078 52656 37538 26630 15925 11265 8864 6682 4744 3055 2146 1396 847 494 320 232 190 105 60 29 16 12 6 6 2 3 3 0 5 3 1 3 0 2 0 1 0 1 0 0 1 2 1 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0 0 

Explanation:

  • 1 = Image value
  • 10500000 = Frequency of image value 1
  • 0 = Number of band
  • 0 = frequency of value 1 in input image
  • 0 = frequency of value 2 in input image
  • 0 = frequency of value 3 in input image
  • ...
  • 1 = frequency of value 20 in input image //1 pixel with value 20
  • ...
  • 4 = frequency of value 32 in input image //4 pixels with value 32

2.2 Calculation of median Landsat DN value using AWK

  • For this we are using the output histogramm_hr.txt from 2.1 as the input:


awk '{obs_point = ($2 - $4)/2} {if (NR == 1) {for(i=5 ; i< NF ; i++) {sum=sum+$i; if(sum >= obs_point) {print i-4; exit}}}}' histogram_hr.txt 


  • The output is printed in the terminal: in our case the median DN values is 48

3. oft-his with option -compact

  • Lets run a oft-his with Input: landsat_t1.tif, Ouptut: histogram_compact.txt, again, the maximum input value to 255
oft-his  -i landsat_t1.tif -o  histogram_compact.txt -compact
head histogram_compact.txt

Extraction of histogram_compact.txt- output is 7 lines (for each band one), which makes it more readable

1 10500000 1 20 1 27 1 28 1 29 2 30 1 31 1 32 4 33 2 34 3 35 5 36 2 37 5 38 8 39 7 40 5 41 176 42 1576 43 12371 44 114959 45 758774 46 1773981 47 2035039 48 1918290 49 1222961 50 558651 51 332962 52 287434 53 320286 54 311067 55 217529 56 180595 57 138396 58 93221 59 57114 60 38722 61 32169 62 25924 63 18311 64 12510 65 9783 66 7020 67 5022 68 3874 69 3116 70 2294 71 1647 72 1193 73 848 74 632 75 408 76 284 77 185 78 163 79 134 80 72 81 73 82 41 83 16 84 11 85 8 86 10 87 4 88 5 89 7 90 10 91 4 92 6 93 2 94 2 96 2 97 1 98 2 99 3 101 1 102 2 103 2 104 2 105 1 107 1 109 1 110 1 111 1 112 1 114 1 115 1 116 3 117 1 118 1 120 1 121 2 122 1 126 2 128 1 129 2 130 1 132 1 138 1 139 1 144 1 147 1 152 1 156 1 165 2 168 1 169 1 174 1 176 1 180 1 187 1 196 1 206 1 208 1 220 1 246 1 255 2

1 10500000 2 1 1 2 1 4 3 5 2 7 2 8 3 9 2 10 3 12 3 13 3 14 2 15 26 16 646 17 8742 18 191086 19 2508329 20 4562947 21 718031 22 338584 23 429870 24 487321 25 333295 26 255746 27 231077 28 161926 29 99078 30 52656 31 

Explanation:

  1. 1 = image value
  2. 10500000 = Frequency of image value 1
  3. 1 = Number of band

After that, the output consists of value-frequency pairs. More detailed: the pair 20 1 means that 1 pixel of value 20 was found within the region determined by image value 1. Also a single pixel with value 27 was found and the number of pixels with value 28 was again 1.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools