difference between in2int16 and int16

3 次查看(过去 30 天)
Hello,
I am trying to read in a 16 bit unsigned image and convert it into 16 bit signed image. I used the function im2int16 and my R,G and B planes have negative values, where as if I use just int16, these planes have positive values. What is the difference between the two?
Also to plot histogram, should I use histogram function or imhist function ? Please explain me the difference.
Thank you.

回答(1 个)

Guillaume
Guillaume 2017-3-15
As per the documentation of im2int16, it rescales the data as necessary, meaning that if the orginal values are not already int16, it will rescale to the int16 range (-32768 to +32767). So a double array in the range [0 1] will result in an int16 array in the range [-32768 32767].
int16 just change the type of the array without changing the values (except for rounding to integers obviously). So a double array in the range [0 1] will result in an int16 array whose values are only 0 or 1.
For your histogram, use whichever function you prefer. imhist will give you more information but both generate an histogram.
  2 个评论
Deep P
Deep P 2017-3-15
Thank you Guillaume. But what if my original values are int 16? How is the rescaling performed? IS it advisable to use int16 or im2int16?
Guillaume
Guillaume 2017-3-15
If the image class is already int16, then it left untouched by either function.
Which function to use depends on the use case. If the values are already in the int16 range but just the wrong type, then use int16 to cast the image to the correct type. If the image is of another type and in the range of that type (e.g. double in the [0-1] range, or uint8 in the [0-255] range) then use im2int16.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by