Convert the intensity of image into a specific intensity range

22 visualizzazioni (ultimi 30 giorni)
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 Commento
Rik
Rik il 2 Ago 2020
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.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 2 Ago 2020
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 Commenti
Image Analyst
Image Analyst il 7 Ago 2020
Modificato: Image Analyst il 7 Ago 2020
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 il 9 Ago 2020
Modificato: SaHaR il 9 Ago 2020
That's true.
Thank you Image Analysit. You always give correct and comprehensive answers :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by