1

I am running gdalinfo -hist on a 3 band tif file and am getting the following output (see below). Notice it says 256 buckets from -78 to 40184. That's fine, but then when it shows the histogram, there are many values outside of that range. For example, the first value is 54449114. Now, I'm sure my knowledge of this is incorrect, but it isn't as intuitive as I had thought.

Does anyone know why those values are outside of the range given?

    256 buckets from -78.6392 to 40184.6:
  54449114 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 464 5609 48048 370511 1250886 2062296 3066844 3590384 3078717 2438408 1890283 1503170 1210255 1019931 891923 802846 729409 673356 625626 570119 512165 453609 397771 343501 299242 262775 226660 194108 167554 149381 132311 121639 110745 104197 96385 91422 90099 87747 86053 83175 82196 80127 78858 76942 74119 73337 73345 72669 71774 68528 67715 66545 66350 66688 67472 67934 68059 67706 68567 68491 69215 70287 69764 69817 70118 70895 70608 72636 73435 75490 75585 75998 76910 77730 78609 79912 81614 82829 83595 85508 85820 86607 86473 87946 87699 88229 88143 87870 86036 85937 83902 80968 78892 77172 75321 73829 72455 72511 72039 71621 72178 72950 72997 73349 73740 72714 72003 71399 71289 68312 66424 64541 63797 61637 60094 59555 57767 56027 55836 55666 55098 55349 56093 56498 57430 58078 59626 60033 60554 61697 63216 63684 65384 66450 67407 68956 70828 72667 73060 75231 76251 76797 78459 79330 81645 82940 84723 85939 87102 86654 87635 89188 90073 90688 91252 91362 91381 91410 91153 89915 87795 86539 85623 83479 81952 81485 80696 79058 76774 76931 73634 72044 70945 69718 66964 65476 62910 59715 55824 52996 50387 46552 43444 39887 36543 32998 29454 26254 23222 19948 16684 13897 11144 8847 6808 5181 3987 3072 2329 1813 1380 1032 739 582 436 288 220 137 70 40 24 19 15 5 1

As a note - I am writing scripts to merge three satellite imagery bands and then brighten them automatically using the -scale flag. My thought is that I can use the histogram to do this.

  • 2
    That number is the count of pixels included in the corresponding bucket. – user30184 Aug 9 '18 at 18:09
  • Oh ok, I see. So the first bucket is 0 (or black), and then the last one is 255 (or fully green, blue, or red, depending on which band it is in). Is that correct? Or is the first bucket -78.6392, and the second bucket is -78.6392 + (40184.6- -78.6392)/256? Or am I way off here? Thanks! – jonesy19 Aug 9 '18 at 18:30
  • 1
    The range between min and max is divided into 256 classes and number of pixels in each class is reported. That's how histograms are created. – user30184 Aug 9 '18 at 20:21
  • Ok, thank you very much. This is helpful. One last question - what does a negative value represent? I get the positive values, but what is a negative value? – jonesy19 Aug 9 '18 at 20:29
  • OK thank you - So it says Computed Min/Max=0.000,45575.000. Is this the range of values for the histogram (and if so, the 256 classes are between those values, evenly spaced)? I have tried to research this with GDAL, but I really have not found any documentation on how the -hist flag works. If there is documentation out there that I am missing, I am totally happy to go through it. – jonesy19 Aug 9 '18 at 20:39
2

Open the file [imagename.ext].aux.xml and you will see where the numbers are coming.

<PAMDataset>
  <PAMRasterBand band="1">
    <Histograms>
      <HistItem>
        <HistMin>-0.5</HistMin>
        <HistMax>255.5</HistMax>
        <BucketCount>256</BucketCount>
        <IncludeOutOfRange>1</IncludeOutOfRange>
        <Approximate>0</Approximate>
        <HistCounts>639|56|1|3|1|0|4|4|2|0|1|0|2|0|2|5|8|4|8|15|8|8|1|5|2|1|1|2|2|1|3|2|0|0|2|1|1|3|2|1|1|1|4|3|3|1|5|6|3|4|4|4|2|1|6|5|3|3|4|4|10|8|9|7|9|9|11|11|3|10|14|18|31|14|22|22|23|32|29|31|31|24|38|45|54|43|43|34|37|36|45|30|38|31|27|27|28|20|24|24|27|21|22|21|24|23|28|21|23|16|22|31|19|23|20|19|18|10|17|6|14|11|10|8|13|13|11|12|7|5|7|5|3|8|5|5|4|5|7|6|3|2|5|3|3|2|6|1|0|5|1|1|0|0|1|0|1|0|2|0|0|1|0|1|3|0|0|2|0|0|0|0|0|1|0|0|0|0|1|0|0|1|0|0|2|1|2|1|0|0|0|0|1|1|1|0|0|0|1|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|1|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|0|0|0|0|0|0</HistCounts>
      </HistItem>
    </Histograms>
  </PAMRasterBand>
  <PAMRasterBand band="2">
    <Histograms>
      <HistItem>
        <HistMin>-0.5</HistMin>
        <HistMax>255.5</HistMax>
        <BucketCount>256</BucketCount>
        <IncludeOutOfRange>1</IncludeOutOfRange>
        <Approximate>0</Approximate>
        <HistCounts>588|41|33|10|10|6|

.....

<HistMin>-0.5</HistMin> = minimum value of the histogram range
<HistMax>255.5</HistMax> = maximum value of the histogram range
<BucketCount>256</BucketC = number of classes in the histogram

Calculating (max-min)/(bucket count) gives the width of the value range that is put into each bucket. In this case each value has an own bucket. In your case you get more units to each bucket by the formula:

((40184.6)-(-78.6392))/256 = 1569.403753125

And then finally number of pixels in each bucket is listed:

<HistCounts>639|56|1|3|1|....

A separate histogram is created for each band of the image.

The GDAL documentation about the usage of the function that computes histograms can be found from https://www.gdal.org/classGDALRasterBand.html#aa21dcb3609bff012e8f217ebb7c81953

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.