Query DICOM Header

Author: Anthony Padua (padua001@mc.duke.edu)
Duke University Medical Center, Department of Radiology
History: 2003/04/21: First version
2003/05/12: Can be called from macros
Source: Query_Dicom_Header.java
Installation: Download Query_Dicom_Header.class to the plugins folder and restart ImageJ.
Description: This plugin is no longer needed. Instead, plugins and scripts can call the DicomTools.getTag() method. Here is a JavaScript example:
   imp = IJ.openImage("https://imagej.nih.gov/ij/images/ct.dcm.zip");
   studyDescription = DicomTools.getTag(imp, "0008,1030");
   imagePosition = DicomTools.getTag(imp, "0020,0032");
   pixelSpacing = DicomTools.getTag(imp, "0028,0030");
   print("Study Description: "+ studyDescription);
   print("Image Position: "+imagePosition);
   print("Pixel Spacing: "+ pixelSpacing);
Macros can use the getInfo() function:
   studyDescription = getInfo("0008,1030");
   imagePosition = getInfo("0020,0032");
   pixelSpacing = getInfo("0028,0030");
   print("Study Description: "+ studyDescription);
   print("Image Position: "+imagePosition);
   print("Pixel Spacing: "+ pixelSpacing);
This plugin queries the DICOM header to return the value for given criterion. A typical search string would look like "0020,0013", but without the double quotes.

The latest version of QDH plugin (requires v1.30m) is now "macro-able": the DICOM header can easily be queried in a macro, and the result of the query can then be used by the macro. Because the results are returned to the results table in differing formats depending on whether the returned result is numeric or non-numeric, the Type field in the results table is used to differentiate numeric data (type=1) from non-numeric data (type=2) from missing or invalid data (type=9).

Usage is particularly straightforward if the [group,element] query returns a numeric result; this can be accessed by a macro using the getResult function. If the [group, element] query returns a non-numeric result, this result is appended to the name of the attribute after a colon and placed in the Attribute column. This can then be accessed from the results table using the getInfo function followed by the split function to divide the contents of the results table into lines, then the lines into fields, and then the appropriate field into two items divided by a colon. As an example, the following macro will print the value of a DICOM [group, element] in the log table, whether numeric or non-numeric ([group,element]=[0008,0025] is used as an example).

run("Clear Results");
run("Set Measurements...", "decimal=3");
run("Query Dicom Header", "9=0008,0025");
typechk = getResult("Type",0);
if (typechk == 9) x= "INVALID";
if (typechk == 1) x = getResult("ValNum",0);
if (typechk == 2) {
   data = getInfo();
   lines = split(data, '\n');
   fields = split(lines[1], '\t');
   items = split(fields[1],':');
   x = items[1];
print (x);

|Plugins | Home |