Remove all frames but the first

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
michar
Posts: 8
Joined: Wed, 2018-04-04, 07:54

Remove all frames but the first

#1 Post by michar »

My code is basically the equivalent of dcmcjpeg except it works in memory like this:

Code: Select all

DcmInputBufferStream dataBuf;
dataBuf.setBuffer(inP, inL);
dataBuf.setEos();

DcmFileFormat fileformat;
fileformat.transferInit();
OFCondition cond = fileformat.read(dataBuf);
if (cond.bad()) ...
fileformat.transferEnd();

DcmDataset *dataset = fileformat.getDataset();
... change representation dataset->chooseRepresentation(...

DcmOutputBufferStream outStream(outP, outL);
fileformat.transferInit();
cond = fileformat.write(outStream, opt_oxfer, opt_oenctype, NULL, opt_oglenc, opt_opadenc, (Uint32) opt_filepad, (Uint32) opt_itempad);
fileformat.transferEnd();

void* p=NULL;
offile_off_t l=0;
outStream.flushBuffer(p, l);

In the case of multiframe images I need the result buffer to only contain the first frame all the others need to be discarded.

How can this be achieved ? any help appreciated.

Thanks!
Micha

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

Re: Remove all frames but the first

#2 Post by J. Riesmeier »

Could you please describe in more details what you want to do? What is the input, what the expected output, transfer syntax of input/output...

michar
Posts: 8
Joined: Wed, 2018-04-04, 07:54

Re: Remove all frames but the first

#3 Post by michar »

Input is a dicom file and output is the same dicom file compressed to JPEG

My code is exactly like dcmcjpeg including all possible switches etc except it works in memory.

The code works fine.

What I need is that in the case of multiframe images I want to load&compress the first frame only

So after I have the DcmFileFormat I need a way tpo remove all frames except the first before calling 'write'

Another way of phrasing this question - how can I modify the code of dcmjpeg.cc so that in the case of multiframes it will only convert/process the first frame ?

I hope this is clearer ?
Thanks!

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

Re: Remove all frames but the first

#4 Post by J. Riesmeier »

Since there is only a decodeFrame() and no encodeFrame() method for the various compression schemes, one way of doing this would be to extract the first frame from the Pixel Data instance using getUncompressedFrame(), which supports both uncompressed and compressed pixel data as input, and to either replace the value of the Pixel Data element with this data or to feed it directly into the desired encoder. Of course, you also need to adapt all relevant DICOM header attributes such as NumberOfFrames.

Alternatively, you could first compress the complete Pixel Data and then remove all Pixel Items but the first two (assuming that you do not use fragmented items). If the first item contains a non-empty Basic Offset Table, its value should also be adapted. Of course, this approach is not very efficient when the input image contains many frames (see value of NumberOfFrames element).

michar
Posts: 8
Joined: Wed, 2018-04-04, 07:54

Re: Remove all frames but the first

#5 Post by michar »

Thank you !

We definitely need to do this before compression.

Is there any existing example or code showing removing frames (ie as you described by removing them, replacing pixeldata and updating dicom fields, or in some other way) ?

Post Reply

Who is online

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