When I change the representation of a dataset, a lot of memory is consumed. I'm searching for a way to reduce the memory usage.
The related forum posts I could find were:
viewtopic.php?f=1&t=4149
viewtopic.php?f=1&t=3214
Unfortunately it didn't gave the information I sought.
Currently I'm testing with an uncompressed multiframe dataset. Using the jpeg compression example, I've created the following test:
Code: Select all
DJEncoderRegistration::registerCodecs();
DcmFileFormat fileformat;
if (fileformat.loadFile(argv[1]).good())
{
DcmDataset *dataset = fileformat.getDataset();
DcmItem *metaInfo = fileformat.getMetaInfo();
DJ_RPLossless params;
dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, ¶ms);
if (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax))
{
delete metaInfo->remove(DCM_MediaStorageSOPClassUID);
delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID);
fileformat.saveFile(argv[2], EXS_JPEGProcess14SV1TransferSyntax);
}
}
DJEncoderRegistration::cleanup();
When the representation is changed, the DcmPixelData::encode(...) method will load the entire multiframe pixelData blob into memory (via DcmPolymorphOBOW::getUint16Array(pixelData)). This array is fed into DcmCodecList::encode(...), which creates the compressed jpeg frames. Now both the original pixelData and the compressed version reside in memory.
When saving the jpeg representation to file, or sending it over the network, there is no need to keep the entire dataset (in both compressed and uncompressed form) in memory. Is there a way to avoid the compression until needed, and release the memory afterwards?
In other words:
- load dataset (without pixel data)
- change representation (but don't load & convert pixel data yet)
- save / send dataset => when the frames are written, use DcmPixelData::getUncompressedFrame(...), compress single frame, store compressed frame, and release frame memory.
Thanks,
Wijnand