Load DICOM image, binarize, and save a new DICOM image

조회 수: 3 (최근 30일)
georgina company
georgina company 2024년 5월 1일
댓글: georgina company 2024년 5월 2일
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
Walter Roberson
Walter Roberson 2024년 5월 1일
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
georgina company 2024년 5월 2일
Der both,
I guess it is what Sir Roberson suggests. However, if I save the binarized image without the info when I construct the MedicalVolume it says that PatientPosition is needed.
Then, how can I construct the medical Volume?

댓글을 달려면 로그인하십시오.

채택된 답변

Karl
Karl 2024년 5월 2일
Two things that might help are:
  1. Convert the binarized image to type double.
  2. Redefine the minimum and maximum greyscale values in the DICOM info.
I give an example below, based on your code.
% Read and display example DICOM image.
dicom1 = 'CT-MONO2-16-ankle.dcm';
info1 = dicominfo(dicom1);
image1 = dicomread(info1);
imshow(image1, [min(image1(:)),max(image1(:))])
% Binarize image, and write to DICOM.
dicom2 = 'binarized.dcm';
bw = double(imbinarize(image1));
info1.SmallestImagePixelValue = min(bw(:));
info1.LargestImagePixelValue = max(bw(:));
dicomwrite(bw,dicom2,info1);
% Read and display binarized image.
info2 = dicominfo(dicom2);
image2 = dicomread(info2);
imshow(image2)
  댓글 수: 9
Image Analyst
Image Analyst 2024년 5월 2일
Try using [] in imshow:
imshow(image2, [])
georgina company
georgina company 2024년 5월 2일
It works fine!
REALLY THANK YOU FOR YOUR HELP!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 DICOM Format에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by