Multiframe compression by file

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
henry
Posts: 9
Joined: Sat, 2011-11-05, 16:24

Multiframe compression by file

#1 Post by henry »

Hi,
my purpose is to compress a multiframe object using little memory as possible.
In my test I set the dicom element and 'link' the uncompressed pixel data through DcmPixelData::createValueFromTempFile method, then I choose the representation and save the object in jpeg lossless format. The result is achieved but during the operation the memory size up to the uncompressed pixel data size when was executed the DcmDataset::chooseRepresentation method, this is ok, the documentation is clear but:
Is possible to convert the data without loading all uncompressed frames in memory ?

Thanks in advance

this is the code I used:

Code: Select all

 
 DcmFileFormat fileformat;
 DcmDataset *dataset = fileformat.getDataset();
 ...
 dataset->putAndInsertString(DCM_PatientName, "Doe^John");
 ...
 dataset->putAndInsertUint16(DCM_Rows,rows);
 dataset->putAndInsertUint16(DCM_Columns,columns);
 dataset->putAndInsertUint16(DCM_SamplesPerPixel,samples_per_pixel);
 dataset->putAndInsertUint16(DCM_BitsAllocated, bits_allocated);
 dataset->putAndInsertUint16(DCM_BitsStored,bits_stored);
 ...
 DcmPixelData *dpix = new DcmPixelData(DCM_PixelData);
 dpix->createValueFromTempFile(new DcmInputFileStreamFactory(pix_data_path.c_str(),0), pixel_data_size, EBO_unknown);
 dataset->insert(dpix, OFFalse, OFFalse); 
 ...
 DJEncoderRegistration::registerCodecs();
 E_TransferSyntax Xfer = EXS_JPEGProcess14SV1TransferSyntax;
 ...
 DJ_RPLossless RPLossless((int)SectionValue, (int)PointTransform);
 const DcmRepresentationParameter *DcmRepParam = &RPLossless;
 ...
 dataset->chooseRepresentation(Xfer, DcmRepParam); 
 if (dataset->canWriteXfer(Xfer))
 {
   ...
 }
 else
 {
   ... 
 } 
 fileformat.saveFile(output_file.c_str(), Xfer);
 ...

Uli Schlachter
DCMTK Developer
Posts: 120
Joined: Thu, 2009-11-26, 08:15

#2 Post by Uli Schlachter »

The short version: No

The long version:
When a pixel element is compressed, the compression codec already receives all the data in memory, so the uncompressed data will be loaded before the codec is run. This is done because all codecs can't easily compress partial data (e.g. by compressing each pixel line by itself) and thus writing a general framework which makes use of partial delayed loading wouldn't have much benefit.

Sorry.

henry
Posts: 9
Joined: Sat, 2011-11-05, 16:24

#3 Post by henry »

Thanks for the reply,
Another alternative option would be to consider frames individually, load any single frame then compress it and add to dataset, in this way would have only compressed data in memory, even though the logic is probably a little more complicated.
Could someone tell me approximately how to proceed and/or examples or part of code maybe already present into dcmtk source to be used as a reference ?

Thank you very much for any advice.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest