How to over-write a modified DICOM file?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
artemmikheev
Posts: 24
Joined: Mon, 2018-11-12, 20:01

How to over-write a modified DICOM file?

#1 Post by artemmikheev » Wed, 2021-03-24, 21:24

Hi OFFIS friends,

I want to open DICOM file, remove some tag (like Patient Name), and Save the file over the original file.

I have this simple code:
*********************************************************************
DcmFileFormat* S = NULL;

S = new DcmFileFormat();

S->loadFile( SrcName );;

// CLEAR some DICOM tags here.....

DcmDataset* dtS = S->getDataset();
E_TransferSyntax Stx = dtS->getOriginalXfer();

S->saveFile( DstName,Stx);

**********************************************************************

Everything works fine and as desired if SrcName and DstName are different.
However, when SrcName=DstName (i.e. overwrite), the function produces new file
incorrectly (and diagnostics says "Missing tags"). Also the overwritten file is drastically
smaller in size f.e. 272KB original down to 4.

Could you please let me know how to perform this operation with overwrite of the original file?

Thank you in advance,
-Artem

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

Re: How to over-write a modified DICOM file?

#2 Post by J. Riesmeier » Thu, 2021-03-25, 09:47

By default, the call of loadFile() does not load all element values into main memory, only those that are smaller than 4 kbytes.
You could either increase this value (parameter "maxReadLength" of the method) or call loadAllDataIntoMemory() before saveFile().

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest