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
Compressing and decompressing images file in imagectn
Moderator: Moderator Team
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
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:
The following example shows how to decompress a JPEG-compressed DICOM image file:
However, please note that the transformation might not always be 100% lossless. See newsgroup posting #1 and #2.
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, ¶ms);
// 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
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
Who is online
Users browsing this forum: Ahrefs [Bot], Baidu [Spider], Bing [Bot] and 1 guest