Monica Heddneck
Monica Heddneck

Reputation: 3115

how to render a dicom file's header unreadable

Kind of a strange question, but I'm doing some testing to handle errors when a dicom file's tags can't be read.

Unfortunately I don't have a damaged dicom available.

Specifically, can anyone advise how to apply some sort of incorrectly encoded text tag or some invalid numeric data tag onto the file, such that it can't be read by python's pydicom package?

Upvotes: 1

Views: 583

Answers (1)

Markus Sabin
Markus Sabin

Reputation: 4013

you could have a look at the dcmodify tool from the DCMTK. It can be used to insert, modify and delete attributes. I doubt that it is possible to specify invalid attribute values through the command line, but you could surely modify the source code to accomplish that (except you can definitely write attribute values that exceed the maximum length according to the Value Representation).

My approach would be to create a buffer of characters and write binary data to it. Then pass it to the method that writes the value to the attribute.

Examples:

  • write unicode (UTF-8) sequences which are not a valid unicode character
  • write ascii characters which are not covered by the characterset specified by (0008,0005) - not sure whether pydicom would run into problems but it would be wrong from the DICOM perspective
  • write non-numeric characters to attributes with Value Representation "Decimal String" or "Integer String".
  • formats other than YYYYMMDD for VR "Date"
  • formats other than HHMMSS.FFFFFF for VR "Time"
  • other characters than ['0'-'9'], '.' for VR "Unique Identifier"

[edit]: DCMTK, dcmodify: http://dicom.offis.de/dcmtk.php.en

Upvotes: 2

Related Questions