After a bit of digging into the internals of Import I figured that some value representations were not handled correctly, as required by the DICOM standard. I would call this a bug, but don't have the reputation to set the flag. If I load the package for importing DICOM files manually
(*Pre-load the DICOM import package to be able to overwrite it. *)
Get[FileNameJoin[{$InstallationDirectory, "SystemFiles", "Kernel", "SystemResources", $SystemID, "Convert", "Dicom.mx"}]]
I can overwrite the function ReadData to fix the problem:
(* Overwrite ReadData to fix the Switch Statement *)
System`Convert`DicomDump`ReadData[
System`Convert`DicomDump`s_,
System`Convert`DicomDump`info_,
System`Convert`DicomDump`ExplicitVR,
System`Convert`DicomDump`rules_
] := Module[
{
System`Convert`DicomDump`len,
System`Convert`DicomDump`VR
},
System`Convert`DicomDump`VR =
BinaryReadList[System`Convert`DicomDump`s, "Character8", 2];
If[
MemberQ[System`Convert`DicomDump`VR, EndOfFile]
,
Return[EndOfFile]
];
System`Convert`DicomDump`VR =
StringJoin[System`Convert`DicomDump`VR];
System`Convert`DicomDump`len = Switch[
System`Convert`DicomDump`VR,
(*Alternatives["OB","OW","SQ","UN","UT"],*)
Alternatives["OB", "OD", "OF", "OL", "OW", "SQ", "UC", "UN", "UR",
"UT"],
Last[
BinaryRead[
System`Convert`DicomDump`s, {"Character8", "Character8",
"UnsignedInteger32"}]],
Alternatives["AE",
"AS", "AT", "CS", "DA", "DS", "DT", "FL", "FD", "IS", "LO",
"LT", "PN",
"SH", "SL", "SS", "ST", "TM", "UI", "UL", "US"(*, "UT"*)
],
BinaryRead[System`Convert`DicomDump`s, "UnsignedInteger16"],
_,
System`Convert`DicomDump`VR = "UN";
BinaryRead[System`Convert`DicomDump`s, "UnsignedInteger16"]
];
If[
System`Convert`DicomDump`len === EndOfFile
,
Return[EndOfFile]
];
System`Convert`DicomDump`read[
System`Convert`DicomDump`s,
System`Convert`DicomDump`info,
System`Convert`DicomDump`VR,
System`Convert`DicomDump`len,
System`Convert`DicomDump`rules
]
]
Note that I've left the incomplete set of alternatives as a comment.
With this modification, I can import the DICOM file correctly.
The unresolved tag names can be resolved with an additional set of replacement rules, which I've posted here:
tagnames.m
I couldn't figure out how to inject this into the import package, so I've simply added it as an additional replacement:
meta = Import["example.dcm", "MetaInformation"];
(* Remove one long private meta information to make things nicer *)
metaShort = meta /. tagNames /. ("(0021,1019)" -> l_List) :> ("(0021,1019)" -> Short[l]);
metaShort //. l : {_Rule ..} :> Grid[l //. (a_ -> b_) :> {a, b}
, Alignment -> {Left, Top}
, Frame -> True
, Background -> {None, {{GrayLevel[0.9], GrayLevel[0.95]}}}
]
The result is a readable version of the meta information, only the private tag names are unresolved, as expected.