필터 지우기
필터 지우기

difference between in2int16 and int16

조회 수: 2 (최근 30일)
Deep P
Deep P 2017년 3월 15일
댓글: Guillaume 2017년 3월 15일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by