Why does the "im2uint16" function convert my image to binary?

I am reading in a TIFF file which contains data stored as uint16.  I am then performing image processing that converts values to the double datatype, but leaves the numerical value unchanged.  In order to write the resulting image to a new TIFF file I am converting this data back to uint16 using the "im2uint16" function but it is changing my image to binary. When I inspect this final image data, it only contains 0's and 65,535's.  Why is this happening? 

 Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 15 Nov. 2022

0 Stimmen

This is occurring because of how the "im2uint16" function handles inputs of the double datatype.  It expects doubles in the 0 to 1 range, which is how image data is typically stored. Any double value greater than 1 is treated as a logical and interpreted to be the maximum unsigned 16-bit integer value of 65,535.
To fix this, either modify your processing to not cast to double, or use the "uint16" function instead which casts doubles to uint16 datatype without interpreting them as image data.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by