Convert the intensity of image into a specific intensity range

24 ビュー (過去 30 日間)
SaHaR
SaHaR 2020 年 7 月 29 日
編集済み: SaHaR 2020 年 8 月 9 日
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
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
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
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
SaHaR
SaHaR 2020 年 8 月 9 日
編集済み: SaHaR 2020 年 8 月 9 日
That's true.
Thank you Image Analysit. You always give correct and comprehensive answers :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by