I have a ct image that values of pixel of it is between 0-4000 how can I convert it to an image with 0-255 ?
이전 댓글 표시
채택된 답변
추가 답변 (2개)
Guillaume
2014년 9월 5일
If the image is stored as double, then Yawar's answer is correct. If your image is stored as uint16, then it won't work, you'll have to convert the image to double first.
For most image processing function to work correctly on an image in the range 0-255, it needs to be of type uint8. If the type is double, most functions assume the range 0-1.
The following is guaranteed to work:
img8bit = im2uint8(double(img) / 4000);
This is equivalent to:
img8bit = uint8(double(img)/4000 * 255);
댓글 수: 3
Christin Panjaitan
2014년 9월 5일
So then, how to convert it back to the original size ? just make it like this :
return16bit = im2uint16(img8bit);
??
Guillaume
2014년 9월 5일
I'm not sure what you mean by original size. The size of the image isn't changed, just the intensity range and the type.
If you want to go back from a uint8 image to an image in the range 0-4000:
img12bitish = double(img8bit) / 255 * 4000;
%or to store it as uint16
img12bitish = uint16(double(img8bit) / 255 * 4000);
Your code return16bit = im2uint16(img8bit) will convert the image to the range 0-65535.
Christin Panjaitan
2014년 9월 5일
I have tried your code.
[1] img12bitish = double(img8bit) / 255 * 4000; %it might return to the original range but the original value has been changing.
For the word of "size", I mean range. Sorry, I just wrong to use the word.
Yawar Rehman
2014년 9월 5일
img = (img / 4000) * 255;
댓글 수: 1
Iain
2014년 9월 5일
This'd be better....
img = double(img);
img = img - min(img(:));
maximum = max(img(:));
img = (img / maximum) * 255;
카테고리
도움말 센터 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!