12bit to 8 bit and Windowing

15 vues (au cours des 30 derniers jours)
David Großmann
David Großmann le 19 Jan 2020
Commenté : David Großmann le 21 Jan 2020
Hallo,
I try to dicomread a 12bit-pic, change it to 8bit and windows it.
With
im = dicomread("CTA_Head.dcm");
im8 = uint8(im-1);
imshow(im8, [LOW,HIGH]);
Everything works fine. Matlab cuts all the values that aren't relevant and turns them into white or black.
But is there a function that does the same without directly displaying the picture?
When I use the following pictures do not look the same(it's darker):
im = dicomread("CTA_Head.dcm");
[nrows ncols] = size(im);
for c = 1:ncols
for r = 1:nrows
if (im(r,c) < LOW)
im2(r,c) = 0;
elseif (im(r,c) > HIGH)
im2(r,c) = 255;
else
im2(r,c) = im(r,c);
end
end
end
im8er = uint8(im2);
imshow(im8er);
Shall I cast to uint8 before or after cutting the values?
Thank You!
  1 commentaire
Guillaume
Guillaume le 20 Jan 2020
If im is 12-bit (integer I presume), this is a very odd thing to do:
im8 = uint8(im-1);
If the 12 bit is signed (range [-2048, 2047]), this rescale im to the range [-2049, 2046] (assuming the 12-bits are stored in a 16-bit integer since matlab doesn't have 12 bit type) which is then clipped to [0 255] by the conversion to uint8. So it maps all values between -2048 and 1 included to 0, maps 1-256 to 0-255 and maps 256+ to 255.
If the 12 bit is unsigned (range [0 4095]), this rescale im to [0 4094] which is then clipped to [0 255]. So it maps 0 and 1 to 0, 2-256 to 1-255 and 256+ to 255.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 19 Jan 2020
In older MATLAB see mat2gray, which has a deceptive function name and is not restricted to grayscale like the name suggests.
In newer MATLAB rescale()
  3 commentaires
Walter Roberson
Walter Roberson le 20 Jan 2020
scaled = (double(im) - LOW) ./ (HIGH - LOW);
im8er = im2uint8(scaled);
David Großmann
David Großmann le 21 Jan 2020
Wow thanks, this looks perfectly fine!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by