Following http://www.exiftool.org/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?
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 (https://exiftool.org/TagNames/XMP.html#DICOM), but with ExifTool's user-defined tags (https://exiftool.org/config.html) you could add any others that you need. If you use the same names as the DICOM-format tags (https://exiftool.org/TagNames/DICOM.html), 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
Thanks, a lot of the tags have been copied automatically to [PNG] with
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:
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.
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 (https://exiftool.org/TagNames/XMP.html#DICOM) for a list of standard DICOM XMP tags that ExifTool can write.
- Phil
Thanks für the explanation, but you didn't explain why
exiftool -overwrite_original -tagsfromfile "$FILE" "-xmp:all<dicom:all" -ext png "$PNGFILE94"does not work
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"`Quote90 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?
Quote from: linuxuser on July 25, 2013, 04:54:35 AM
Thanks für the explanation, but you didn't explain why
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 FILEDo 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
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.
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 (https://exiftool.org/TagNames/XMP.html#DICOM) 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 (https://exiftool.org/config.html) for any other tags you want copied.
- Phil
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?
Quote from: linuxuser on July 28, 2013, 10:24:17 AM
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
Quoteyou 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
Quoteexiftool -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.
Quote from: linuxuser on July 28, 2013, 01:38:58 PM
your suggestion
Quoteexiftool -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
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.
No, the 2nd command copies a subset of the tags from the 1st command.
- Phil