Reference to non-existent field 'PixelSpacing'.
Show older comments
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)
Walter Roberson
on 7 May 2018
0 votes
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
Stelios Fanourakis
on 7 May 2018
Stelios Fanourakis
on 7 May 2018
Walter Roberson
on 7 May 2018
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.
Stelios Fanourakis
on 7 May 2018
Walter Roberson
on 7 May 2018
Edited: Walter Roberson
on 7 May 2018
Guessed_spacing = repmat(randi([1 50]), 2, 1);
info = dicominfo('YourFile.dcm');
data = dicomread(info);
info.PixelSpacing = Guessed_spacing;
dicomwrite(data, 'YourNewFile.dcm', info);
Walter Roberson
on 7 May 2018
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.
Stelios Fanourakis
on 7 May 2018
Stelios Fanourakis
on 7 May 2018
Edited: Stelios Fanourakis
on 7 May 2018
Stelios Fanourakis
on 7 May 2018
Edited: Stelios Fanourakis
on 7 May 2018
Walter Roberson
on 7 May 2018
When you do dicominfo on the original file does the modality show up as OT ("other") or as US ("ultrasound")?
Stelios Fanourakis
on 8 May 2018
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!