Author Topic: How to write DICOM Tags somehow  (Read 6824 times)

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
How to write DICOM Tags somehow
« on: July 17, 2013, 05:08:56 AM »
Following http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/DICOM.html DICOM-Tags are not writeable, but readable.

I have compressed DICOM-files and assume they are jpg2000-compressed, but I can be wrong. I try to make the images easier readable, so I do the following using linux with dcmp2pgm

dcmp2pgm converts the compressed image to pgm
convert from Imagemagick with -quality 93 creates a png file
exiftool should write all the original metadata with -tagsfromfile to the png file.

Since the DICOM-group is not writeable, important data is missing.

What would be the easiest way to get all the original meta-data into the png-file?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #1 on: July 17, 2013, 07:39:09 AM »
The only way I can think of would be to write the DICOM metadata to XMP in the PNG image.  There are already a number of standard DICOM XMP tags, but with ExifTool's user-defined tags you could add any others that you need.  If you use the same names as the DICOM-format tags, then copying them to PNG should be as easy as this:

exiftool -tagsfromfile %d%f.dicom "-xmp:all<dicom:all" -ext png DIR

Where this command copies all DICOM tags in .dicom files to XMP tags in .png files for all PNG files in directory DIR.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
Re: How to write DICOM Tags somehow
« Reply #2 on: July 24, 2013, 05:31:59 PM »
Thanks, a lot of the tags have been copied automatically to [PNG] with

Code: [Select]
convert "$FILE" -quality 94 "$PNGFILE"
eg:

Quote
[PNG]                - Dcm Body Part Examined          : CSPINE

Unfortunately, I tried with an example image which was pure black, so I was confused. My images are not compressed.

I want to edit the tags file by file and not the whole dir at once, so I tried in a bash-script:

Code: [Select]
convert "$FILE" -quality 94 "$PNGFILE94"
exiftool -q -q -overwrite_original -tagsfromfile "$FILE" "$PNGFILE94"
exiftool -overwrite_original -tagsfromfile "$FILE" "-xmp:all<dicom:all" -ext png "$PNGFILE94"

But I cannot see Dicom-Tags, except the ones from the 2nd line.



Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #3 on: July 24, 2013, 06:34:12 PM »
The tags in PNG format are non-standard, and you would need to create user-defined tags to write these.

See the DICOM tags in the XMP tags documentation for a list of standard DICOM XMP tags that ExifTool can write.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
Re: How to write DICOM Tags somehow
« Reply #4 on: July 25, 2013, 04:54:35 AM »
Thanks für the explanation, but you didn't explain why

Code: [Select]
exiftool -overwrite_original -tagsfromfile "$FILE" "-xmp:all<dicom:all" -ext png "$PNGFILE94"
does not work

Code: [Select]
      ORIGINALTAGS=`exiftool -G -H -a "$FILE" | wc -l`
echo "$ORIGINALTAGS lines in "`basename "$FILE"`
echo

convert "$FILE" -quality 94 "$PNGFILE94"
CONVERTEDTAGS=`exiftool -G -H -a "$PNGFILE94" | wc -l`
echo "$CONVERTEDTAGS lines in "`basename "$PNGFILE94"`
XMPTAGS=`exiftool -G -H -a "$PNGFILE94" | grep "XMP" | wc -l`
echo "$XMPTAGS lines with XMP in "`basename "$PNGFILE94"`
echo

exiftool -q -q -overwrite_original -tagsfromfile "$FILE" "$PNGFILE94"
CONVERTEDTAGS=`exiftool -G -H -a "$PNGFILE94" | wc -l`
echo "$CONVERTEDTAGS lines (-tagsfromfile) in "`basename "$PNGFILE94"`
XMPTAGS=`exiftool -G -H -a "$PNGFILE94" | grep "XMP" | wc -l`
echo "$XMPTAGS lines (-tagsfromfile) with XMP in "`basename "$PNGFILE94"`
echo

exiftool -q -q -overwrite_original -tagsfromfile "$FILE" "-xmp:all<dicom:all" -ext png "$PNGFILE94"
CONVERTEDTAGS=`exiftool -G -H -a "$PNGFILE94" | wc -l`
echo "$CONVERTEDTAGS lines (-tagsfromfile -xmp) in "`basename "$PNGFILE94"`
XMPTAGS=`exiftool -G -H -a "$PNGFILE94" | grep "XMP" | wc -l`
echo "$XMPTAGS lines (-tagsfromfile -xmp) with XMP in "`basename "$PNGFILE94"`


Quote
90 lines in 07299246.dcm

75 lines in 20070110__soab_7299246_094648.656000.png
0 lines with XMP in 20070110__soab_7299246_094648.656000.png

87 lines (-tagsfromfile) in 20070110__soab_7299246_094648.656000.png
10 lines (-tagsfromfile) with XMP in 20070110__soab_7299246_094648.656000.png

87 lines (-tagsfromfile -xmp) in 20070110__soab_7299246_094648.656000.png
10 lines (-tagsfromfile -xmp) with XMP in 20070110__soab_7299246_094648.656000.png

The dicom-file contains 90 lines. After the conversion to png with convert from Imagemagick the png-file has 75 lines, but no XMP-tag. Obviously something was lost. -tagsfromfile increases the lines to 87, adding 10 lines / tags to XMP. But "-tagsfromfile -xmp" doesn't add / copy more XMP-tags.

Is the commandline wrong?



Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #5 on: July 25, 2013, 07:40:48 AM »
Thanks für the explanation, but you didn't explain why

Code: [Select]
exiftool -overwrite_original -tagsfromfile "$FILE" "-xmp:all<dicom:all" -ext png "$PNGFILE94"
does not work

I can't answer this because I don't know what metadata is in the file.

Use this command to see what tags exist:

exiftool -a -G1 -s FILE

Do any DICOM tags exist?  Or are all of your DICOM tags written in PNG format?  If PNG, then you need to change DICOM to PNG in your command.  Also, check to see if same-named tags exist in the ExifTool XMP-dicom tags.  If not, nothing will get written.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
Re: How to write DICOM Tags somehow
« Reply #6 on: July 25, 2013, 09:11:09 AM »
I think "-ext png" is not necessary, but it didn't work too after I have removed it.

Phil, I will send you a dicom-sample. Please keep the image and the metadata private.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #7 on: July 28, 2013, 09:47:48 AM »
I got the sample.  Extracting the information from the PNG image with exiftool -G1 -s shows that the information exists in tags like the following:

PNG:dcmAcquisitionDate
PNG:dcmAcquisitionNumber
PNG:dcmAcquisitionTime
[etc]

So there are 2 problems copying these to XMP:

1) The corresponding XMP tags do not a a "dcm" prefix on their name.  Also, there are some other minor differences in the tag names.  Since the tags have different names, they must be copied individually, like this:

exiftool "-PatientBirthDate<dcmPatientsBirthDate" "PatientID<dcmPatientsID" ...

You can create an argument file and use the -@ option to avoid typing all of these on the command line.

2) The list of standard XMP-dicom tags is not complete, so many of your PNG "dcm" tags have no XMP counterpart.  The only way to get around this is to create user-defined tags for any other tags you want copied.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
Re: How to write DICOM Tags somehow
« Reply #8 on: July 28, 2013, 10:24:17 AM »
Thanks for looking at my sample.

So the PNG-tags, which were created by convert from IM, cannot be ignored and the XMP-tags in the png-file cannot be creadted with -tagsfromfile using the orginal file, which has dicom-tags only?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #9 on: July 28, 2013, 12:55:17 PM »
So the PNG-tags, which were created by convert from IM, cannot be ignored and the XMP-tags in the png-file cannot be creadted with -tagsfromfile using the orginal file, which has dicom-tags only?

False.

Actually, I didn't realize you sent a DICOM-format file too.  If copying from the DICOM file, problem number 1 goes away and you are just left with problem number 2 (creating user-defined tags for any other XMP-dicom tags you want to create that aren't already part of ExifTool).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
Re: How to write DICOM Tags somehow
« Reply #10 on: July 28, 2013, 01:38:58 PM »
Quote
you are just left with problem number 2 (creating user-defined tags for any other XMP-dicom tags you want to create that aren't already part of ExifTool).

Can I copy some dicom-tags to xmp with "-tagsfromfile" without creating user-defined tags? As already written before, your suggestion

Quote
exiftool -tagsfromfile %d%f.dicom "-xmp:all<dicom:all" -ext png DIR

didn't work.

Please try it with my 2 sample file to import some dicom-metadata of the dicom-file into to png-file as xmp-metadata without creating using-defined tags.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #11 on: July 28, 2013, 06:45:11 PM »
your suggestion

Quote
exiftool -tagsfromfile %d%f.dicom "-xmp:all<dicom:all" -ext png DIR

didn't work.

Yes it did.  Observe the XMP in the PNG sample you sent.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

linuxuser

  • Sr. Member
  • ****
  • Posts: 107
Re: How to write DICOM Tags somehow
« Reply #12 on: July 28, 2013, 07:11:32 PM »
Code: [Select]
exiftool -q -q -overwrite_original -tagsfromfile "$FILE" "$PNGFILE94"
exiftool -overwrite_original -tagsfromfile "$FILE" "-xmp:all<dicom:all" -ext png "$PNGFILE94"

Ok, now I think I understand. The xmp-tags in the png-file I got with the 1st exiftool command, I thought I get more with the 2nd line.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: How to write DICOM Tags somehow
« Reply #13 on: July 29, 2013, 06:55:35 AM »
No, the 2nd command copies a subset of the tags from the 1st command.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).