on the fly (de)compression

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Geert Vandenbussche
Posts: 12
Joined: Tue, 2018-11-13, 09:05

on the fly (de)compression

#1 Post by Geert Vandenbussche » Sun, 2022-08-07, 18:03

DCMTK 3.6.6
I'm trying to implement on the fly (de)compression with the following code framework:

Code: Select all

DcmSCU scu;
...
if (fileformat.loadFile(sLocation, EXS_Unknown, EGL_recalcGL, DCM_MaxReadLength, ERM_fileOnly).good())
{
...
	if (fileformat.getDataset()->chooseRepresentation(EXS_LittleEndianImplicit, NULL).bad() && fileformat.getDataset()->canWriteXfer(EXS_LittleEndianImplicit))
	{
   		BOOST_LOG_SEV(lg, error) << "Conversion failed.";
	}
	else
	{
   		BOOST_LOG_SEV(lg, info) << "Conversion succeeded.";
	}
...
DcmDataset* ds = fileformat.getDataset();
result = scu.sendSTORERequest(0, NULL, ds, rspStatusCode);
When processing a CT Image with JPEG Lossless, Non-hierarchical, 1st Order Prediction as transfer syntax, the log indicates that the conversion has succeeded, but sending over the dataset fails:
2022-08-07 09:31:05.588 DEBUG: ===================== OUTGOING DIMSE MESSAGE ====================
2022-08-07 09:31:05.588 DEBUG: Message Type : C-STORE RQ
2022-08-07 09:31:05.588 DEBUG: Presentation Context ID : 3
2022-08-07 09:31:05.588 DEBUG: Message ID : 2
2022-08-07 09:31:05.588 DEBUG: Affected SOP Class UID : CTImageStorage
2022-08-07 09:31:05.588 DEBUG: Affected SOP Instance UID : 1.2.752.37.1.1.157718784.20101210.6.6407
2022-08-07 09:31:05.588 DEBUG: Data Set : present
2022-08-07 09:31:05.588 DEBUG: Priority : medium
2022-08-07 09:31:05.588 DEBUG: ======================= END DIMSE MESSAGE =======================
2022-08-07 09:31:05.588 WARN: DIMSE Warning: (SCU,STORESCP): sendMessage: unable to convert dataset from 'JPEG Lossless, Non-hierarchical, 1st Order Prediction' transfer syntax to 'JPEG Lossless, Non-hierarchical, 1st Order Prediction'
2022-08-07 09:31:05.588 ERROR: Failed sending C-STORE request: 0006:020e DIMSE Failed to send message
2022-08-07 09:31:05.592 DEBUG: DcmMetaInfo::checkAndReadPreamble() TransferSyntax="Little Endian Explicit"
2022-08-07 09:31:05.592 DEBUG: DcmDataset::read() TransferSyntax="JPEG Lossless, Non-hierarchical, 1st Order Prediction"
2022-08-07 09:31:05.593 DEBUG: Start of Image
2022-08-07 09:31:05.593 DEBUG: Start Of Frame 0xc3: width=512, height=512, components=1
2022-08-07 09:31:05.593 DEBUG: Component 0: 1hx1v q=0
2022-08-07 09:31:05.593 DEBUG: Miscellaneous marker 0xfe, length 14
2022-08-07 09:31:05.593 DEBUG: Define Huffman Table 0x00
2022-08-07 09:31:05.593 DEBUG: Start Of Scan: 1 components
2022-08-07 09:31:05.593 DEBUG: Component 0: dc=0 ac=0
2022-08-07 09:31:05.593 DEBUG: Ss=1, Se=0, Ah=0, Al=0
2022-08-07 09:31:05.597 DEBUG: End Of Image
If I delete 'if (fileformat.getDataset()->chooseRepresentation(EXS_LittleEndianImplicit, NULL).bad() && fileformat.getDataset()->canWriteXfer(EXS_LittleEndianImplicit))' and recompile, the object is sent over correctly.

Am I missing something?
Thanks!

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1352
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: on the fly (de)compression

#2 Post by Marco Eichelberg » Wed, 2022-08-17, 13:38

The call to chooseRepresentation() causes DCMTK to decompress the image and to then discard the JPEG compressed original. This explains why sending in JPEG lossless fails after decompression.
The problem is that in some cases decompression requires changes in the main dataset (e.g. Photometric Interpretation), and does not keep different "versions" of entire datasets. In order to make sure that an inconsistent dataset (consisting of a modified main dataset and the unmodified compressed data), the compressed version is discarded during decompression. If you want to continue to handle both, you need to copy the entire dataset object (e.g. see DcmDataset::clone())

Geert Vandenbussche
Posts: 12
Joined: Tue, 2018-11-13, 09:05

Re: on the fly (de)compression

#3 Post by Geert Vandenbussche » Thu, 2022-08-18, 09:37

Thanks Marco,

The issue was related to the PresentationContextID in the sendSTORERequest. If 0 is used, the PresentationContextID is used which relates to the original dataset, even after

Code: Select all

ds->chooseRepresentation(EXS_LittleEndianImplicit,NULL);
resulting in the error.
If the PresentationContextID is changed to the one represented with the correct Abstract Syntax and UID_LittleEndianImplicitTransferSyntax as Transfer Syntax, everything is working as expected.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest