geotiff.js icon indicating copy to clipboard operation
geotiff.js copied to clipboard

Float32 images with predictors decoded incorrectly

Open kevinmehall opened this issue 7 years ago • 2 comments

I generated 3 test files from the same source file with:

gdalwarp -t_srs EPSG:4326 -r med -ts 500 0 -co COMPRESS=LZW -co NUM_THREADS=4 -co TILED=YES -co PREDICTOR=1 dsm.tif out_1.tif
gdalwarp -t_srs EPSG:4326 -r med -ts 500 0 -co COMPRESS=LZW -co NUM_THREADS=4 -co TILED=YES -co PREDICTOR=2 dsm.tif out_2.tif
gdalwarp -t_srs EPSG:4326 -r med -ts 500 0 -co COMPRESS=LZW -co NUM_THREADS=4 -co TILED=YES -co PREDICTOR=3 dsm.tif out_3.tif

Output files uploaded here The files display identically in QGIS.

I wrote a script to decode with this library, and print the first pixel value, a pixel value near the center, the number of pixels with valid data, and the min and max pixel value:

const geotiff = require('geotiff')
const fs = require('fs')
const file = geotiff.parse(fs.readFileSync(process.argv[2]).buffer)
const image = file.getImage(0)
const data = image.readRasters()

console.log(data[0][0], data[0][113476])

let min = Infinity
let max = -Infinity
let count = 0
for (v of data[0]) {
  if (v !== -10000 && !Number.isNaN(v)) { // these files contain value -10000 where the value is undefined
    min = Math.min(min, v)
    max = Math.max(max, v)
    count++
  } 
}

console.log(count, min, max)

For the files encoded using the predictors, the results are incorrect:

$ node test.js ../out_1.tif 
-10000 3.233187437057495
178661 1.7235643863677979 23.675439834594727
$ node test.js ../out_2.tif 
-10000 NaN
3062 -3.0305079947271845e+38 6.5514631170016586e+35
$ node test.js ../out_3.tif 
2.7745709593631378e-43 NaN
89457 -Infinity 6.64613997892458e+35

kevinmehall avatar Jun 23 '17 17:06 kevinmehall

Perfect, thanks, I'll investigate ASAP

constantinius avatar Jun 23 '17 17:06 constantinius

@kevinmehall I finally got around to fix this (as with 8caab99). All three of your supplied files now work and are decoded to the same array.

Some edge cases are not yet thoroughly tested (e.g: floating point predictor with multiple bands pixel interleaved)

Could you test this and confirm that this issue is resolved?

constantinius avatar Feb 23 '18 09:02 constantinius