Reference to non-existent field 'PixelSpacing'.

I have a dicom viewer that cannot load ultrasound images because of that error (see subject line). What to do?
I get the error for that line of the dicom viewer
scale=[info.PixelSpacing(1) info.PixelSpacing(2) info.SliceThickness];

Answers (1)

You use dicominfo() to read the metadata. You use dicomread() on the metadata to read the content of the image. You set the PixelSpacing field in the metadata. You dicomwrite() of the content of the image and the metadata into a new file.
Or... you fix the viewer, or get a new viewer.
See https://www.mathworks.com/matlabcentral/answers/215612-how-can-i-convert-pixels-to-mm-for-a-specific-dicom-image#answer_178301 for more information about correctly computing position information for DICOM files.

11 Comments

I used dicominfo for the ultrasound images. Do not have any value such as PixelSpacing
I saw from CT dicom images that the PixelSpacing is [2*1 double]. Can I apply this to ultrasound dicom images?
Look at the link I gave and read the references there to see what kind of information is expected to exist, and look at the information you do have available and figure out what values are needed in order to meaningfully fake it. And then you write them into the metadata the way I described.
I told you. Ultrasound images DO not have PixelSpacing values at their metadata. I need to import those values to them. How do I do this?
Guessed_spacing = repmat(randi([1 50]), 2, 1);
info = dicominfo('YourFile.dcm');
data = dicomread(info);
info.PixelSpacing = Guessed_spacing;
dicomwrite(data, 'YourNewFile.dcm', info);
Look at info.SequenceOfUltrasoundRegions at the content there. In the sample ultrasound image I found, it has Item_1 and Item_2 . For example,
>> info.SequenceOfUltrasoundRegions.Item_1
ans =
struct with fields:
RegionSpatialFormat: 1
RegionDataType: 1
RegionFlags: 2
RegionLocationMinX0: 80
RegionLocationMinY0: 28
RegionLocationMaxX1: 944
RegionLocationMaxY1: 568
ReferencePixelX0: 512
ReferencePixelY0: 28
PhysicalUnitsXDirection: 3
PhysicalUnitsYDirection: 3
ReferencePixelPhysicalValueX: 0
ReferencePixelPhysicalValueY: 0
PhysicalDeltaX: 0.00277428146175764
PhysicalDeltaY: 0.00277428146175764
The PhysicalUnits*Direction coded as 3 indicate cm; see https://dicom.innolitics.com/ciods/us-image/us-region-calibration/00186011/00186026
You want the one that has RegionSpatialFormat 1, which is "2d (tissue or flow), not RegionSpatialFormat 4, which is waveform such as eeg traces or Dopler.
So the pixel spacing was 0.00277428146175764 cm in X and Y. To convert this to PixelSpacing you would need to multiply by 10, because PixelSpacing is in mm http://dicom.nema.org/dicom/2013/output/chtml/part03/sect_10.7.html
I found this information by grabbing a sample DICOM image from https://medistim.com/dicom/ and looking to see what information was available in the file, and then I looked it up online to see what the units were.
How can I use dicominfo for a matrix of images? Such as
for indx=1:15
A = dicomread(strcat( 'D:\stelios phd files\DesMoines\' , int2str(indx),'.dcm'));
Guessed_spacing= repmat(randi([1 50]), 2, 1);
info = dicominfo(A);
data = dicomread(info);
info.PixelSpacing = Guessed_spacing;
dicomwrite(data, 'B.dcm', info);
end
It won't accept dicominfo(A). Comes up with error, "Error using fopen First input must be a file name or a file identifier."
I used this
for indx=1:15
A = dicomread(strcat( 'D:\stelios phd files\DesMoines\' , int2str(indx),'.dcm'));
Guessed_spacing= repmat(randi([1 50]), 2, 1);
info.PixelSpacing = Guessed_spacing;
dicomwrite(A, strcat('D:\stelios phd files\DesMoines\red', int2str(indx) , '.dcm'), info);
end
But still my DICOM Viewer won't open them
This is the dicominfo list I get after implementing the above code.
Filename: 'D:\stelios phd files\DesMoines\red1.dcm'
FileModDate: '07-May-2018 17:27:38'
FileSize: 855146
Format: 'DICOM'
FormatVersion: 3
Width: 592
Height: 481
BitDepth: 8
ColorType: 'truecolor'
FileMetaInformationGroupLength: 208
FileMetaInformationVersion: [2×1 uint8]
MediaStorageSOPClassUID: '1.2.840.10008.5.1.4.1.1.7'
MediaStorageSOPInstanceUID: '1.3.6.1.4.1.9590.100.1.2.231857289913218636708538082840642054664'
TransferSyntaxUID: '1.2.840.10008.1.2'
ImplementationClassUID: '1.3.6.1.4.1.9590.100.1.3.100.9.4'
ImplementationVersionName: 'MATLAB IPT 9.4'
SOPClassUID: '1.2.840.10008.5.1.4.1.1.7'
SOPInstanceUID: '1.3.6.1.4.1.9590.100.1.2.231857289913218636708538082840642054664'
StudyDate: ''
ContentDate: '20180507'
StudyTime: ''
ContentTime: '172738.348000'
AccessionNumber: ''
Modality: 'OT'
ConversionType: 'WSD'
ReferringPhysicianName: [1×1 struct]
PatientName: [1×1 struct]
PatientID: ''
PatientBirthDate: ''
PatientSex: ''
SecondaryCaptureDeviceManufacturer: 'MathWorks'
SecondaryCaptureDeviceManufacturerModelName: 'MATLAB'
StudyInstanceUID: '1.3.6.1.4.1.9590.100.1.2.317346425713416810703901124010557130218'
SeriesInstanceUID: '1.3.6.1.4.1.9590.100.1.2.92426240512972478022251411762047641361'
StudyID: ''
SeriesNumber: []
InstanceNumber: []
PatientOrientation: ''
SamplesPerPixel: 3
PhotometricInterpretation: 'RGB'
PlanarConfiguration: 0
Rows: 481
Columns: 592
BitsAllocated: 8
BitsStored: 8
HighBit: 7
PixelRepresentation: 0
When you do dicominfo on the original file does the modality show up as OT ("other") or as US ("ultrasound")?

Sign in to comment.

Categories

Find more on Ultrasound Imaging 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!