Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float32 images with predictors decoded incorrectly #28

Open
kevinmehall opened this issue Jun 23, 2017 · 2 comments
Open

Float32 images with predictors decoded incorrectly #28

kevinmehall opened this issue Jun 23, 2017 · 2 comments

Comments

@kevinmehall
Copy link

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
@constantinius
Copy link
Member

Perfect, thanks, I'll investigate ASAP

@constantinius
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants