Unable to compress a dcm file in Linux (CentOS7)

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
shahvezakhtar007
Posts: 9
Joined: Tue, 2017-07-04, 09:27

Unable to compress a dcm file in Linux (CentOS7)

#1 Post by shahvezakhtar007 »

Hi,

I am using dcmtk3.6.0, i am not able to compress any file.

Return value of chooseRepresentation api is "Illegal call, perhaps wrong parameters"

Original transfer syntax: Explicit VR Little Endian
Target Transfer syntax: JPEG Lossless, Nonhierarchical, First- Order Prediction(Processes 14 [Selection Value 1])

I am using CentOS 7.

What could be the possible reasons?

Regards,

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

Re: Unable to compress a dcm file in Linux (CentOS7)

#2 Post by J. Riesmeier »

Does it work to compress this particular DICOM image file with "dcmcjpeg", i.e. from the command line?

shahvezakhtar007
Posts: 9
Joined: Tue, 2017-07-04, 09:27

Re: Unable to compress a dcm file in Linux (CentOS7)

#3 Post by shahvezakhtar007 »

Yes, it works while using dcmcjpeg from terminal.

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

Re: Unable to compress a dcm file in Linux (CentOS7)

#4 Post by J. Riesmeier »

OK, did you make sure that the JPEG encoders are registered to your program? See example in the documentation for details.

shahvezakhtar007
Posts: 9
Joined: Tue, 2017-07-04, 09:27

Re: Unable to compress a dcm file in Linux (CentOS7)

#5 Post by shahvezakhtar007 »

Yes they are registered.
Here is the code I am using:

int DcmtkDicomInterface::ConvertDicom(std::string inputFile, std::string outputFile)
{
DJEncoderRegistration::registerCodecs();
OFCondition chooseRepresentationStatus;

DcmFileFormat fileformat;
if (fileformat.loadFile(inputFile.c_str()).good())
{
RAD_LOG_INFO("Processing DICOM file " << inputFile.c_str());
DcmDataset *dataset = fileformat.getDataset();
DcmItem *metaInfo = fileformat.getMetaInfo();
DJ_RPLossless params;

chooseRepresentationStatus = dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, &params);
RAD_LOG_CRITICAL("Choose Representation status is : " << chooseRepresentationStatus.text());

if (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax))
{
RAD_LOG_INFO("Can write JPEG lossless");
// force the meta-header UIDs to be re-generated when storing the file
// since the UIDs in the data set may have changed
delete metaInfo->remove(DCM_MediaStorageSOPClassUID);
delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID);
// store in lossless JPEG format
fileformat.saveFile(outputFile.c_str(), EXS_JPEGProcess14SV1TransferSyntax);
DJEncoderRegistration::cleanup();
return 1;
}
DJEncoderRegistration::cleanup();
return (-1);
}
}

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

Re: Unable to compress a dcm file in Linux (CentOS7)

#6 Post by J. Riesmeier »

Further questions: What does the DEBUG logger show?
Did you make sure that the data dictionary is loaded?
The latter can be checked with the following code (from "dcmdata.cc"):

Code: Select all

    /* make sure data dictionary is loaded */
    if (!dcmDataDict.isDictionaryLoaded())
    {
      OFLOG_WARN(dcmdumpLogger, "no data dictionary loaded, check environment variable: "
        << DCM_DICT_ENVIRONMENT_VARIABLE);
    }

shahvezakhtar007
Posts: 9
Joined: Tue, 2017-07-04, 09:27

Re: Unable to compress a dcm file in Linux (CentOS7)

#7 Post by shahvezakhtar007 »

Data dictionary was not loaded.
It didn't work even though the environment variable 'DCMDICTPATH' was set to the dicom.dic file.
I rebuilt dcmtk libraries with the flag 'DCMTK_ENABLE_BUILTIN_DICTIONARY' enabled in CMake.
Now its working.

THANK YOU for your help.

Post Reply

Who is online

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