How imagej convert 16bit to 8bit?

Dear forum
Does someone know which math function is used in ImageJ to convert 16bit grayscale to 8bit grayscale?
The one used by Menu->Image->Type->8bit

thanks
Emanuele

Here is the Java source:

thanks some ignorance here…
what (pixels16[i]&0xffff) will do?

The bottom line of this question is to replicate the 16bit to 8bit conversion in Matlab.

See:

http://imagej.1557.x6.nabble.com/Handling-signed-and-unsigned-16-bit-images-td3693185.html

See also:

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

https://forum.unity.com/threads/bitwise-operation-on-integers-what-does-x-16-and-x-0xffff-do-numerically.862753/

https://imagej.nih.gov/ij/docs/guide/146-28.html#toc-Subsection-28.1

1 Like