Compressing and decompressing images file in imagectn

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Erik
Posts: 3
Joined: Mon, 2005-01-31, 10:33

Compressing and decompressing images file in imagectn

#1 Post by Erik »

I am interested in modifying the imagectn server to compress incoming image files using the DICOM default lossless compression and decompress outgoing image file. Should I add support in saveFile for writeTransfersyntax set to lossless JPEG in the imagectn module or should imagectn call the dcmdjpeg and dcmcjpeg tools instead? Any advice would be much appreciated.

Regards
Erik

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

Basically, it's quite easy to add support for image compression and decompression to an application. From the toolkit's documentation:

The following example shows how to compress a DICOM image file with lossless JPEG:

Code: Select all

DJEncoderRegistration::registerCodecs(); // register JPEG codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test.dcm").good())
{
  DcmDataset *dataset = fileformat.getDataset();
  DcmItem *metaInfo = fileformat.getMetaInfo();
  DJ_RPLossless params; // codec parameters, we use the defaults

  // this causes the lossless JPEG version of the dataset to be created
  dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, &params);

  // check if everything went well
  if (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax))
  {
    // 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("test_jpeg.dcm", EXS_JPEGProcess14SV1TransferSyntax);
  }
}    
DJEncoderRegistration::cleanup(); // deregister JPEG codecs
The following example shows how to decompress a JPEG-compressed DICOM image file:

Code: Select all

DJDecoderRegistration::registerCodecs(); // register JPEG codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test_jpeg.dcm").good())
{
  DcmDataset *dataset = fileformat.getDataset();

  // decompress data set if compressed
  dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);

  // check if everything went well
  if (dataset->canWriteXfer(EXS_LittleEndianExplicit))
  {
    fileformat.saveFile("test_decompressed.dcm", EXS_LittleEndianExplicit);
  }
}    
DJDecoderRegistration::cleanup(); // deregister JPEG codecs
However, please note that the transformation might not always be 100% lossless. See newsgroup posting #1 and #2.

Post Reply

Who is online

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