0

I'm trying to do thresholding with the CV2 Python module to binarize a raster image so that vegetation = 1 and everything else = 0. The problem is that when I pick a reasonable value to do the thresholding with CV (in Python) I just get a black output raster. I messed around and made a histogram to figure out why and this is what I see:

enter image description here

What's going on here? The actual values range from up to 2530 (I truncated the value from 0-20 because there's nothing after x = 7.5.) I changed the threshold value in CV2 to 2 and the output looks good now, but that doesn't explain why the greyscale values aren't matching up what's in QGIS.

I suspect this might have something to do with how many bits the data has. It's currently in an unsigned 16 bit format. I can't get it down to 8 bit unsigned...just "byte".

Here's what I've tried:

  1. raster -> convert -> transform to change the raster image to 8 bytes.
  2. toolbox -> SAGA -> raster normalization to change the pixel range from 0-255.

No dice! How do I fix this?

Your Answer

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

Browse other questions tagged or ask your own question.