Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use "Cast Image" VI to go from 32bit image to 8bit image?

I have converted a 32 bit array to an image, but the cast_image vi just puts out a black image when I then try to convert it to an 8 bit image. The help file for cast_image only mentions converting in every other possible direction, does that mean that I can't convert from 32 to 8 bit? I have tried using the shift input, but that didn't help(& I amnot totally sure what that is doing).
0 Kudos
Message 1 of 3
(3,351 Views)
That is 32 bit grayscale(SGL), btw....

Thanks.
0 Kudos
Message 2 of 3
(3,350 Views)
vtphotonics,
 
Good question.  It looks like I need to write a Knowledgebase on this question.  When you cast from a single (32bit float) to a U8, you are not grabbing the 8 most significant bits of the single (like casting from I16 to U8).  Rather the float value is converted to a U8 the same way LabVIEW coerces a Float to U8.
 
For example +255 float (01000011011111110000000000000000) will be converted to U8 255 (11111111), not (01000011).
 
I realize this is extremely confusing if you are expecting the cast to happen on a bit level.  The cast function does not actually cast the data in this case rather it converts the data.
 
If you want to only extract the 8 most signficant bits, I would cast the data to a U8 before converting the array to an image.
 
I hope I answered your question,
Lorne Hengst
Application Engineer
Message 3 of 3
(3,332 Views)