0

I am trying to perform a simple contrast stretch with python skimage on the image opened with gdal as array of type float32. I first calculate the percentile with:

p2, p98 = np.percentile(arrayF, (P1, P2))

and then try to perform the stretch with:

img_rescale = exposure.rescale_intensity(arrayF, in_range=(p2, p98))

The returned image written to .tiff with GDAL contains only 'ones' and nodata. The cause of the problem might be in data range. For this arrayF it is between 0,0352989 and 1,03559. The script Works fine when stretching the array with values 0 - 255.

1

Sounds like a datatype issue. When arrayF is float type, the default output data range is also float, i.e. [0., 1.]. Try specify output data type:

a = np.random.rand(3, 3)
[[ 0.69539188  0.95485996  0.89813273]
[ 0.44711894  0.64000582  0.37857347]
[ 0.10434298  0.37033454  0.3290399 ]]
print exposure.rescale_intensity(a)
[[ 0.69492898  1.          0.93330265]
[ 0.40302072  0.62980852  0.32242801]
[ 0.          0.31274104  0.26418864]]
print exposure.rescale_intensity(a, out_range='uint8')
[[ 177.20689067  255.          237.9921748 ]
[ 102.77028316  160.60117291   82.21914229]
[   0.           79.74896403   67.36810315]]

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.