반응형

compress a DICOM image file with lossless JPEG

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
  if (dataset->chooseRepresentation(EXS_JPEGProcess14SV1, &params).good() &&
      dataset->canWriteXfer(EXS_JPEGProcess14SV1))
  {
    // store in lossless JPEG format
    fileformat.saveFile("test_jpeg.dcm", EXS_JPEGProcess14SV1);
  }
}
DJEncoderRegistration::cleanup(); // deregister JPEG codecs

decompress a JPEG-compressed DICOM image

DJDecoderRegistration::registerCodecs(); // register JPEG codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test_jpeg.dcm").good())
{
  DcmDataset *dataset = fileformat.getDataset();
 
  // decompress data set if compressed
  if (dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL).good() &&
      dataset->canWriteXfer(EXS_LittleEndianExplicit))
  {
    fileformat.saveFile("test_decompressed.dcm", EXS_LittleEndianExplicit);
  }
}
DJDecoderRegistration::cleanup(); // deregister JPEG codecs

compress a DICOM image file with lossless JPEG-LS

 

DJLSEncoderRegistration::registerCodecs(); // register JPEG-LS codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test.dcm").good())
{
  DcmDataset *dataset = fileformat.getDataset();
  DcmItem *metaInfo = fileformat.getMetaInfo();
  DJLSRepresentationParameter rp(0, OFTrue); // parameters for lossless
 
  // this causes the lossless JPEG-LS version of the dataset to be created
  dataset->chooseRepresentation(EXS_JPEGLSLossless, &params);
 
  // check if everything went well
  if (dataset->canWriteXfer(EXS_JPEGLSLossless))
  {
    // store in lossless JPEG-LS format
    fileformat.saveFile("test_jpls.dcm", EXS_JPEGLSLossless);
  }
}
DJLSEncoderRegistration::cleanup(); // deregister JPEG-LS codecs

decompress a JPEG-LS compressed DICOM

DJLSDecoderRegistration::registerCodecs(); // register JPEG-LS codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test_jpls.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);
  }
}
DJLSDecoderRegistration::cleanup(); // deregister JPEG-LS codecs

 

반응형

'[====== Development ======] > DICOM' 카테고리의 다른 글

DCMTK on Linux  (0) 2022.08.02
c# fo-dicom Add Sequence Tag  (0) 2022.06.15
DICOM DOSE SR 관련 자료  (0) 2021.09.24
[DCMTK] Source Code 빌드 방법 정리  (2) 2021.08.27
DICOM UID 생성규칙  (0) 2021.08.18

+ Recent posts