getPhotome​tricInterp​retation error when using MultiframeSingleFile option in dicomwrite

34 次查看(过去 30 天)
I have a 3D array in Matlab (64x64x64) representing a modified SPECT image. I am trying to write this to a single DICOM file using the new "MultiframeSingleFile" option in dicomwrite. My syntax is as follows:
dicomwrite(X, 'test.dcm', info, 'CreateMode', 'Copy', 'MultiframeSingleFile', 'true');
Here, "info" is the metadata from the original SPECT dataset, with a few modified tags (UIDs, SeriesDescription, etc). However, when I run this I get the following chain of errors:
Error using dicom_prep_ImagePixel>getPhotometricInterp (line 116)
Cannot determine photometric interpretation.
Error in dicom_prep_ImagePixel (line 10)
metadata.(dicom_name_lookup('0028', '0004', dictionary)) =
getPhotometricInterp(X, map, txfr);
Error in dicom_copy_IOD (line 32)
metadata = dicom_prep_ImagePixel(metadata, X, map, options.txfr,
dictionary);
Error in dicomwrite>write_message (line 268)
[attrs, status] = dicom_copy_IOD(X, map, ...
Error in dicomwrite (line 200)
[status, options] = write_message(X, filename, map, metadata,
options);
I tried explicitly defining:
info.PhotometricInterpretation = 'MONOCHROME2';
...but this doesn't help. If I take out the MultiframeSingleFile option, put the dicomwrite function in a for loop, and write each slice of the data as a separate file, it works correctly.
Digging into the various private Matlab functions responsible for the error, it seems that the Photometric Interpretation is defined inside the dicom_prep_ImagePixel function, and depends on the 3rd dimension of the data being written. If size(X,3) == 1, the photometric interpretation is set to "MONOCHROME2". If size(X,3) == 3, it is set to one of the various colour scales. This seems obviously wrong, since the 3rd dimension in my data is image slices and does not represent colour map data. This therefore seems to be a bug in the implementation of the MultiframeSingleFile option in dicomwrite. I therefore tried hard-coding the PhotometricInterpretation in dicom_prep_ImagePixel (line 10):
%metadata.(dicom_name_lookup('0028', '0004', dictionary)) = getPhotometricInterp(X, map, txfr);
metadata.(dicom_name_lookup('0028', '0004', dictionary)) = 'MONOCHROME2';
With this modification, the data saves without error, and can be re-read into Matlab correctly.
Has anyone else experienced this problem? Am I correct in thinking that this is a bug, or am I doing something else wrong?

采纳的回答

James Scuffham
James Scuffham 2012-7-30
After looking into this some more, I have found the very obvious answer.
Matlab stores DICOM data in a 4D array; the first two dimensions are rows and columns, the third dimension is "colour", and the fourth dimension represents slices.
At some point in my code, I had done:
squeeze(X)
to remove the singleton third dimension. Re-writing the dicomwrite code as follows solves the problem:
dicomwrite(reshape(X,[64 64 1 64]), info, 'CreateMode', 'Copy', 'MultiframeSingleFile', 'true');
  2 个评论
Brett Shoelson
Brett Shoelson 2013-6-27
[a,b,c] = size(X); dicomwrite(reshape(X,[a,b,1,c], info, 'CreateMode', 'Copy', ...'MultiframeSingleFile', true);
Note the change of 'true' to true (no quotes...it's a logical flag, not a string.)
Cheers,
Brett
Ramaprasad Kulkarni
Ramaprasad Kulkarni 2013-10-20
In fact the MultiframeSingleFile option is not required since the option 'true' is default (unless you want to specify it for best practices).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by