Dicom To JpegConvert Code not working

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
abhishekworld
Posts: 10
Joined: Tue, 2010-04-27, 06:16

Dicom To JpegConvert Code not working

#1 Post by abhishekworld »

Hi I have written the code to convert one dicom image to jpeg as follow reference DCMTK doc.
the output image won't open its the corrupted image any idea whats wrong ?

Code: Select all

#define HAVE_CONFIG_H
#include <dcmtk/dcmjpeg/djencode.h>
#include <dcmtk/dcmjpeg/djrplol.h>
#include <dcmtk/dcmdata/dcfilefo.h>
#include <dcmtk/dcmdata/dcdatset.h>
#include <dcmtk/dcmdata/dcitem.h>
#include <dcmtk/dcmdata/dcdeftag.h>

int main()
{
    DJEncoderRegistration::registerCodecs(); // register JPEG codecs
    DcmFileFormat fileformat;
    if (fileformat.loadFile("test.dcm").good())
    {
        DcmDataset *dataset = fileformat.getDataset();
        DcmItem *metaInfo = (DcmItem*)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", EXS_JPEGProcess14SV1TransferSyntax);
        }
    }
    DJEncoderRegistration::cleanup(); // deregister JPEG codecs

    return 0;
}

alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

#2 Post by alwittta »

// store in lossless JPEG format
fileformat.saveFile("test.jpeg", EXS_JPEGProcess14SV1TransferSyntax);
As per the documentation of DCMTK dcmFileFormat class, saveFile is used to save object to DICOM format, and not to jpeg foramt :( .

Post Reply

Who is online

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