> I use dicomlookup to extract only certain tags from images
> in a dicomdir.
> My problem is when a tag is not present in the dicom
> header, in that case dicomlookup stops the routine and I
> get an error message:
> ??? Reference to non-existent field 'ScanOptions'.
> Error in ==> Rdcm>hListboxDirCallback at 244
> dcminfo.ScanMode = gdata.metadata.(dicomlookup
> ('0018','0022')); can mode
> Is there an easy way to work around the problem?
> I'd like to avoid dicominfo because I'm only interested in
> a few tags (to use in the routine, and for display on the
The DICOMLOOKUP function only gives you the name that corresponds to a
(group,element) pair, and vice versa. It doesn't actually communicate
with any files or parse any data. You will still need to use DICOMINFO
to parse the file.
If you have more time than I do to devote to this task, you can actually
hack up a pretty good solution that parses the whole file but doesn't do
the slower post-parsing step that turns *all* of the raw data into what
you would see with DICOMINFO. It's not hard to make this solution, but
there's just too much going on here to actually put a robust, more
usable solution like it into the toolbox. So, good luck...
The DICOM parser in toolbox/images/medformats/private is quite easy to
call and produces a well-contained output:
attrs = dicomparse(fileDetails.name, ...
Be sure to call it with the correct arguments or you can get a
segmentation violation, which is bad. Replace "fileDetails.name" and
"fileDetails.bytes" with the filename and the number of bytes in the
file. Replace getMachineEndian with either 'L' or 'B' depending on
whether you're running on a little-endian machine (Windows, Linux, Intel
Mac) or big-endian machine (other kinds of UNIX hardware). The "false"
value performs some optimizations; I would recommend leaving it as is.
The result is a structure array with these fields:
* Group - A double containing the attribute's group number
* Element - A double containing the attribute's element number
* VR - A two-letter code giving the DICOM datatype (or empty)
* Name - More or less the result of dicomlookup(Group,Element)
* IsLittleEndian - 1 if the attribute contains little-endian data
* Data - Either the raw bytes of the attribute's data or another
structure of attributes containing sequence data
If you go this route, your task is to search "attrs" for the group and
element you're looking for, which is rather easy using something like this:
idx = find(([attrs.Group] == myGroup) & ([attrs.Element] == myElement));
What you do with the values in "attrs(idx).Data" is your business and
will probably depend on what you want to do with the data. Because Data
will contain UINT8 values, you will likely need to transform them into
other MATLAB datatypes that correspond to the actual data intent. Look
to the functions CHAR, TYPECAST, and SWAPBYTES for help. The
translation rules require a fair bit of knowledge about DICOM, but you
can likely find the information you need for simple types in the
convertRawAttr() function in DICOMINFO.
Image Processing Group
The MathWorks, Inc.