How to over-write a modified DICOM file?

All other questions regarding DCMTK

Moderator: Moderator Team

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

How to over-write a modified DICOM file?

#1 Post by artemmikheev »

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: 2498
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 »

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().

frank83
Posts: 5
Joined: Thu, 2021-11-11, 09:32

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

#3 Post by frank83 »

J. Riesmeier wrote: 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.
Just for curiosity, if loadFile(SrcName) does not load all values, how is it possible that saveFile(DstName) works fine only in case SrcName != DstName ?
Is saveFile() calling something like loadAllDataIntoMemory() automatically? why not do the same if SrcName == DstName ?

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

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

#4 Post by J. Riesmeier »

The element value is loaded on demand from the input file. The same is true when the value is accessed via one of the getXXX() methods.
Of course, loading the element values from the input file does not work if the input file is overwritten by the output file.

frank83
Posts: 5
Joined: Thu, 2021-11-11, 09:32

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

#5 Post by frank83 »

That's clear, thanks! :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest