dcmodify -if

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Posts: 32
Joined: Fri, 2012-10-12, 08:05

dcmodify -if

#1 Post by bnoeafk » Thu, 2019-10-24, 02:19

Server running Ubuntu 16.04.6 with dcmodify v3.6.1 2015-09-24 (as per Linux repos for this version of Ubuntu)

I've successfully created a DCM from a PDF using

Code: Select all

pdf2dcm +st /var/lib/dicom/e5/b4/e5b4906c-e5c4-4441-afc0-09f37123e2b7 ./test.dcm
and noted that all tags appear to be correct with a dcmdump test.dcm. However, it's missing a couple of tags that I'd like to include from the source DICOM file (notably AccessionNumber and StudyDescription), so I thought this is the perfect case for using dcmodify and its -if parameter. However it certainly doesn't appear to work as it's noted in the documentation.

Using the same source DICOM file that I used to create the PDF, I've tried the following commands:
  1. dcmodify -nb -if "(0008,0050)=/var/lib/dicom/e5/b4/e5b4906c-e5c4-4441-afc0-09f37123e2b7" ./test.dcm
    • E: DcmObject: Length of element AccessionNumber (0008,0050) exceeds maximum of 16-bit length field
  2. dcmodify -nb -if "0008,0050=/var/lib/dicom/e5/b4/e5b4906c-e5c4-4441-afc0-09f37123e2b7" ./test.dcm
  3. dcmodify -nb -if "AccessionNumber=/var/lib/dicom/e5/b4/e5b4906c-e5c4-4441-afc0-09f37123e2b7" ./test.dcm
  4. dcmodify -nb -if 'AccessionNumber=/var/lib/dicom/e5/b4/e5b4906c-e5c4-4441-afc0-09f37123e2b7' ./test.dcm
    • 2. 3. 4. all return the following E: unable to load file ./test.dcm: I/O suspension or premature end of stream
So I try copying locally to the folder in case the path was too long

Code: Select all

cp /var/lib/dicom/e5/b4/e5b4906c-e5c4-4441-afc0-09f37123e2b7 ./source.dcm
dcmodify -nb -if "AccessionNumber=./source.dcm" ./test.dcm
I still get the I/O suspension error.

I guess from (1) above I shouldn't use the parentheses, which is fine, and of course I could pull the values from the source file, hold them in memory and then use dcmodify -i "(0008,0050)=valueFromSourceFile" ./test.dcm but wanted to see if there was something that I'm missing when using the -if parameter?

PS. To check that the test.dcm file was OK, I was successfully able to run dcmodify -i "(0008,0050)=TESTVALUE" ./test.dcm.
PPS. I also realize that the version for this version of Ubuntu is 4 years old. If this is a bug(?) it may well have been addressed in a later version, but I wanted to ensure I was using the command correctly before moving to a later version (which has it's own issues...)

Jan Schlamelcher
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: dcmodify -if

#2 Post by Jan Schlamelcher » Thu, 2019-10-24, 08:36

bnoeafk wrote:
Thu, 2019-10-24, 02:19
which has it's own issues...
Which ones? I'm currently preparing DCMTK 3.6.5, so I would like to know...

Michael Onken
DCMTK Developer
Posts: 1815
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany

Re: dcmodify -if

#3 Post by Michael Onken » Thu, 2019-10-24, 08:42


the -if option reads the value from a file, BUT it assumes that the whole file is the new value, i.e the file does not necessarily have to be a DICOM file (or almost never is I guess).

So you could create a text file with the desired value of Accession Number inside and use that for -if. This is probably not what you want though. The option was added mostly for adding large values like new Pixel Data from a file.

There is no possibility with dcmodify to "copy" values from an existing DICOM file.

Best regards,

J. Riesmeier
DCMTK Developer
Posts: 2296
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany

Re: dcmodify -if

#4 Post by J. Riesmeier » Thu, 2019-10-24, 09:35

I also think that the OP misinterpreted what option -if is meant for. Reading the documentation and examples in the man page would probably help:

Code: Select all

-if  --insert-from-file:
       dcmodify -if "PixelData=pixel.raw" file.dcm
       Inserts the content of file 'pixel.raw' into the PixelData element
       of 'file.dcm'.  The contents of the file will be read as is.
       OW data is expected to be little endian ordered and will be
       swapped if necessary.  No checks will be made to ensure that the
       amount of data is reasonable in terms of other attributes such as
       Rows or Columns.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest