About the saving processing of the Lossless JPEG image

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Jyunji Kuboya
Posts: 4
Joined: Fri, 2005-02-18, 03:18
Location: Tokyo, Japan

About the saving processing of the Lossless JPEG image

#1 Post by Jyunji Kuboya »

Hi, everybody! :D

I am trying the saving of the Lossless JPEG image.
(At this time, it uses the copy constructor of DcmFileFormat)

When copied DcmFileFormat is saved, PixelData of the saved file is lost.

Condition:
TransferSyntaxUID is "1.2.840.10008.1.2.70".

How should be done the saving processing?

Thanks.

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

#2 Post by Marco Eichelberg »

I would suggest that you look at the implementation of the dcmcjpeg tool. If your source image is created in uncompressed form, you will need to convert it to lossless JPEG representation before you can save in lossless JPEG format. This requires that you register the lossless JPEG codec at runtime and call chooseRepresentation() on the dataset prior to storing the file.

Jyunji Kuboya
Posts: 4
Joined: Fri, 2005-02-18, 03:18
Location: Tokyo, Japan

#3 Post by Jyunji Kuboya »

It goes according to the following procedures.

1.The source image is made in the shape that has already been compressed.

2.The source image is read with DcmFileFormat.

3.New DcmFileFormat is made by handling the copy constructor from read DcmFileFormat.

4.New DcmFileFormat is saved in the file.

5.PixelData of the saved file is lost.

At which stage does it only have to be executed chooseRepresentation()?
PixelData has been lost though chooseRepresentation() was executed ahead of No.4.

:cry: :cry:

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

#4 Post by Jörg Riesmeier »

The following example is part of the toolkit's documentation:

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
If you need a more complex example have a look at the implementation of "dcmcjpeg"!

Jyunji Kuboya
Posts: 4
Joined: Fri, 2005-02-18, 03:18
Location: Tokyo, Japan

#5 Post by Jyunji Kuboya »

This time codes it as follows.

Code: Select all

DJEncoderRegistration::registerCodecs(); // register JPEG codecs 
DcmFileFormat fileformat; 
if (fileformat.loadFile("test.dcm").good()) 
{ 
  //new DcmFileFormat is created by a opened file.
  DcmFileFormat* pFileFormat = new DcmFileFormat(fileformat);

  DcmDataset *dataset = pFileFormat->getDataset(); 
  DcmItem *metaInfo = pFileFormat->getMetaInfo(); 
  DJ_RPLossless params;

  dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, &params); 

  if (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax)) 
  { 
    delete metaInfo->remove(DCM_MediaStorageSOPClassUID); 
    delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID); 

    pFileFormat->saveFile("test_jpeg.dcm", EXS_JPEGProcess14SV1TransferSyntax); 
  } 
}    
DJEncoderRegistration::cleanup(); // deregister JPEG codecs
PixelData is lost when doing according to this procedure.
Cannot DcmFileFormat of copied Lossless JPEG be preserved? :(

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

#6 Post by Jörg Riesmeier »

This is a known bug of DCMTK 3.5.3 which will be fixed in the next release:

Code: Select all

**** Changes from 2004.07.01 (eichelberg)

- Fixed copy constructor for class DcmPixelData which did not work correctly
  under certain circumstances due to an uninitialized attribute.
  Affects: dcmdata/libsrc/dcpixel.cc
Why do you create a copy of "fileformat" anyway?

Jyunji Kuboya
Posts: 4
Joined: Fri, 2005-02-18, 03:18
Location: Tokyo, Japan

#7 Post by Jyunji Kuboya »

A loaded file might be edited.
It occasionally save a file by a different file name.

When saving a file, original "ImplementationVersionName" is added.
Loaded DcmFileFormat is used for a display.

Therefore, the display is likely to differ from DcmFileFormat that executed saveFile() and a file of real existence.

:?

Is there something good idea? :)

Post Reply

Who is online

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