Convert the intensity of image into a specific intensity range
20 次查看(过去 30 天)
显示 更早的评论
Hello everybody,
I have 100 3D medical images that have different intensity ranges. most of them have a maximum intensity of 255( and their type is single) but that of some of them is about 2000-3000( uint16). How can I convert the intensity of all images into [0,255]?
I tried this: 255*( (Img - min(Img(:)))./max(img(:))) but it didn't give the expected result. please help me with this problem.
Thank you.
1 个评论
Rik
2020-8-2
Since this is likely about CT images, you need to decide what window level and width makes sense for your application. Looking for lung nodules requires a very different window than determining emphysema severity.
采纳的回答
Image Analyst
2020-8-2
You can use mat2gray:
Img2 = uint8(255 * mat2gray(Img));
or you can use rescale
Img2 = rescale(Img, 0, 255);
rescale gives a floating point output. Cast to uint8 if you want uint8. Pick whatever min and max you want. We can give a better answer if you tell us why the code you used did not give the expected answer.
5 个评论
Image Analyst
2020-8-7
编辑:Image Analyst
2020-8-7
SaHaR
If we use imhist(), the X axis will be from 0 to 65,535. But your image is not uint16. It is int16. So the gray levels go from -32768 to +32767. But this image does not have all that many unique gray levels. It has fewer so most of its gray levels will be bundled into a few bins. The default number of bins is 256, which means each bin will hold 65535/256 = 256 gray levels. All your gray levels are in the range 0-658. So that's why all your gray levels are in 3 bins: one covering 0-255, the second covering 256-511, and the third covering 512-767. To see more bins, you should specify the bin width using histogram():
Try this:
s = load('image.mat')
grayImage = s.Image;
% This is a SIGNED int16 array, not unsigned uint16 array.
[rows, columns, numberOfSlices] = size(grayImage);
for k = 1 : numberOfSlices
thisSlice = grayImage(:, :, k);
% Display the image.
subplot(numberOfSlices, 2, 2*(k-1)+1);
imshow(thisSlice, []);
axis('off', 'image');
% Display the histogram.
subplot(numberOfSlices, 2, 2*(k-1)+2);
[counts, binLocations] = imhist(thisSlice);
grid on;
% If we use imhist(), the X axis will be from 0 to 65,535
% but this image does not have that many gray levels.
% It has fewer and most of its gray levels will be bundled into a few bins.
% The default number of bins is 256, which means each bin will hold 65535/256 = 256 gray levels.
% Find out what the min and max actually are:
minGL = min(thisSlice(:)); % Turns out to be 0 for every slice.
maxGL = max(thisSlice(:)); % Turns out to be 658 in slice #3.
fprintf('For slice %d, min GL = %d and max GL = %d.\n', k, minGL, maxGL);
% Make the histogram go from 0 to 700:
edges = linspace(0, 700, 100); % 100 bins
histogram(thisSlice, edges);
grid on;
drawnow;
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/343084/image.png)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!