1

I working to invert values of a one-band tif files (download sample).

If i use 254 it works:

$ gdal_calc.py -A ./shadedrelief.tmp.tif  --outfile=whited.tmp.tif  --calc="254*(A>180)" 
0 .. 10 .. 20 .. 30 .. 40 .. 50 .. 60 .. 70 .. 80 .. 90 .. 100 - Done
$ gdallocationinfo -valonly ./whited.tmp.tif 1 1   # we expect 254
254
$ gdal_calc.py -A whited.tmp.tif --outfile=inverted.tif --calc="255-A"
0 .. 10 .. 20 .. 30 .. 40 .. 50 .. 60 .. 70 .. 80 .. 90 .. 100 - Done
$ gdallocationinfo -valonly ./inverted.tif 1 1   # we expect 1 (because 255-A = 255-254)
1 

But the value 255 is troublesome:

$ gdal_calc.py -A ./shadedrelief.tmp.tif  --outfile=whited.tmp.tif  --calc="255*(A>180)" 
0 .. 10 .. 20 .. 30 .. 40 .. 50 .. 60 .. 70 .. 80 .. 90 .. 100 - Done
$ gdallocationinfo -valonly ./whited.tmp.tif 1 1   # we expect 255 
255
$ gdal_calc.py -A whited.tmp.tif --outfile=inverted.tif --calc="255-A"
0 .. 10 .. 20 .. 30 .. 40 .. 50 .. 60 .. 70 .. 80 .. 90 .. 100 - Done
$ gdallocationinfo -valonly ./inverted.tif 1 1   # we expect 0 (because 255-A = 255-255)
255    # <============================ THIS OUTPUT IS NOT EXPECTED.

As far as I know, RGBA range is [0-255]. So...

Why does gdal_calc fails with value 0?


Edit: and for some reason, the 254-based whited.tmp.tif only has 2 type of pixels, so end final.tif also only has transparent [255,0] or black [0,255]. I expected a continuous gradation between the both.

enter image description here

2 Answers 2

1

try --NodataValue=None, and if it doesn't work, you can change the pixel depth to --type='Int16'

1
  • Not successful, added screenshot.
    – Hugolpz
    Apr 30, 2015 at 22:09
0

gdalinfo -mm helps to understand, see the 2 last lines:

$ gdalinfo -mm ./shadedrelief.tmp.tif 
Driver: GTiff/GeoTIFF
Files: ./shadedrelief.tmp.tif
Size is 1980, 2011
Coordinate System is `'
Origin = (67.000000000000000,37.500000000000000)
Pixel Size = (0.016161616161616,-0.016161616161616)
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  67.0000000,  37.5000000) 
Lower Left  (  67.0000000,   4.9989899) 
Upper Right (  99.0000000,  37.5000000) 
Lower Right (  99.0000000,   4.9989899) 
Center      (  83.0000000,  21.2494949) 
Band 1 Block=1980x4 Type=Byte, ColorInterp=Gray
    Computed Min/Max=1.000,255.000
  NoData Value=0

the value 0 is reserved for NoData pixels. So the range is reduced to [1-255].

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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