Dear All, I have an image whose intensity values ranges from -15 to +20. I want to convert it to 8-bit and 16-bit values. Please let me know the algorithm/formula that I can use to program in matlab. In addition, how to save the image in 8-bit and 16 bit in matlab.
regards and thanks

답변 (1개)

Image Analyst
Image Analyst 2016년 6월 26일

0 개 추천

Try this:
image8 = uint8(mat2gray(yourDoubleImage) * intmax('uint8'));
imwrite(fullFileName, image8);
image16 = uint16(mat2gray(yourDoubleImage) * intmax('uint16'));
imwrite(fullFileName, image16);

댓글 수: 4

try analyst
try analyst 2016년 6월 27일
Thanks Image Analyst, Please let me know the conversion ranges from -15 to +20 to 0 to 255 and the code You added is giving error.
Error using * Integers can only be combined with integers of the same class, or scalar doubles.
Thanks in advance for your help.
Try wrapping intmax in double
double(intmax('uint8'))
try analyst
try analyst 2016년 6월 28일
Yes it works but the quality of the image is very bad.
im2uint8 and im2uint16 are simpler for doing the conversion from [0 1] to whichever range:
image8 = im2uint8(mat2gray(yourimage));
image16 = im2uint16(mat2gray(yourimage));
"the quality of the image is very bad"
If it's after saving the image, possibly it's because you're not using an appropriate image format.
If it's after the conversion to uint8 and uint16, then don't do the conversion! By definition, converting to integers is going to discretise your image. Although, with uint16 having 65536 levels of grey, it shouldn't be an issue.

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

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2016년 6월 26일

댓글:

2016년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by