Load DICOM image, binarize, and save a new DICOM image
Show older comments
I load a DICOM Image and binarize it.
Then I save a new dicom image. However, the saved image is only black, and not black and white.
Here is the code:
for i = 1:length(d)
na=d(i).name;
TF = startsWith(na,'Tumour');
if TF == 1
info = dicominfo(na);
greyImage = dicomread(info);
BW=imbinarize(greyImage);
fname1 = strcat('bin_',na)
dicomwrite(BW, fname1,info);
else
if TF == 0
fprintf('File do not match')
end
end
end
4 Comments
Karl
on 1 May 2024
How are you displaying the binarized image after saving it?
I can run this code on a carefully-selected DICOM file, and the binarized result can be read and viewed fine. Your written image is black. Without any information about your image file and how you're viewing it, we cannot know whether this is because:
- something is going wrong with how you're viewing it
- something is going wrong with how you're saving it
- or something is going wrong with how you binarized it to begin with.
I'm going to guess that it's the latter; after all, imbinarize() is not magic. Unless some effort were taken, it might indeed be expected to give garbage results. Did you look at the range of your image data? A lot of DICOM images only use a tiny portion of their available dynamic range. If present, things like annotations, borders, or other decorations may present as features which lie far outside the actual dynamic range of the image data. For example, I have images where:
- the available dynamic range is [-32768 32767]
- the actual image data spans only [-59 101]
- the borders and annotations span [-2048 0]
What do you think will happen when I blindly binarize that?
Again, this is just a guess.
Walter Roberson
on 1 May 2024
dicomwrite(BW, fname1,info);
That asks to write a dicom image using the attributes of the original image. But the attributes of the original image are potentially unsuitable for writing an image of type logical.
georgina company
on 2 May 2024
Accepted Answer
More Answers (0)
Categories
Find more on DICOM Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
