Problem converting and displaying Dicom(ultrasonics) image for Matrix

1 次查看(过去 30 天)
I have a project to read a DICOM file and determine if it is a DICOM file or not. Then read the content of the file and convert it to Matrix and then display it as an image. But unfortunately the picture always appears like this for me
But when I view the image in another program, it appears in its true form
elseif strcmp(Group,'7FE0')
if strcmp(Element,'0010')
if dicom_data{7,5}==16
dcmImage = uint16(fread(fID,[dicom_data{5,5} dicom_data{6,5}],'uint16')');
dicom_data{10,5} = dcmImage;
else
dcmImage = uint16(fread(fID,[dicom_data{5,5} dicom_data{6,5}],'uint8')');
dicom_data{10,5} = dcmImage;
end
else
fseek(fID,ValueLength,0);
end
else
if(ftell(fID)==DateiEnde)
break
end
fseek(fID,ValueLength,0);
end
end
imshow(dicom_data,[0 2^dicom_data{9,5}])
This is the data it reads from the DICOM file
ans =
10×5 cell array
{'TransferSyntax' } {'2' } {'10' } {'UI'} {'1.2.840.10008.1…'}
{'PatientName' } {'10' } {'10' } {'PN'} {'no patient' }
{'SamplesPerPixel'} {'28' } {'2' } {'US'} {[ 3]}
{'NumberOfFrames' } {'28' } {'8' } {'IS'} { 2×1 char }
{'Rows' } {'28' } {'10' } {'US'} {[ 512]}
{'Cols' } {'28' } {'11' } {'US'} {[ 512]}
{'BitsAllocated' } {'28' } {'100'} {'US'} {[ 8]}
{'BitsStored' } {'28' } {'101'} {'US'} {[ 8]}
{'HighBit' } {'28' } {'102'} {'US'} {[ 7]}
{'PixelData' } {'7FE0'} {'10' } {'OB'} {512×512 uint16 }
  7 个评论
Khaled Al Hamidi
Khaled Al Hamidi 2022-5-29
Thank you
I found the problem related to the size of the array, I changed it to another size and the problem was solved
from:
dcmImage = uint8(fread(fID,[dicom_data{5,5} dicom_data{6,5}],'uint8')');
to:
dcmImage = uint8(fread(fID,[1536 512],'uint8')');
but I got a non-rectangular image

请先登录,再进行评论。

回答(1 个)

aditi bagora
aditi bagora 2023-10-10
Hello Khaled,
I understand you want to read a DICOM (ultrasonics) file and extract the values from its metadata. It seems that you are currently using the "fread()" and "fseek()" functions to read the binary file. However, you are encountering issues when reading the pixel data, which could be due to a mismatch in reading the binary data in a particular format or inconsistent data in the file.
To overcome these issues, you can manually try reading the binary file using "fread()" and "fseek()", you can try using the "dicomread()" and "dicominfo()" functions. These functions are specifically designed to read pixel data and metadata from DICOM files, ensuring compatibility and accurate extraction.
To read the pixel data and dicom data, you can refer to the following example code:
pixel_data = dicomread(filename); % read pixel data
imshow(pixel_data);
dicom_data = dicominfo(filename); % To read the DICOM metadata.
Please refer to the following links for more information:
Hope this helps!
Regards,
Aditi

类别

Help CenterFile Exchange 中查找有关 DICOM Format 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by