-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompressDicom.cpp
More file actions
58 lines (54 loc) · 2.07 KB
/
compressDicom.cpp
File metadata and controls
58 lines (54 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/didislut.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmjpeg/djencode.h"
#include "dcmtk/dcmjpeg/djrplol.h"
#include "dcmtk/dcmjpeg/djdecode.h"
void compressDicom(){
DJEncoderRegistration::registerCodecs(); // register JPEG codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test1.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_JPEGProcess14SV1, ¶ms);
// check if everything went well
if (dataset->canWriteXfer(EXS_JPEGProcess14SV1))
{
// 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_JPEGProcess14SV1);
}
}
DJEncoderRegistration::cleanup(); // deregister JPEG codecs
}
void decompressDicom(){
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
}
int main(int argc, char const *argv[])
{
compressDicom();
decompressDicom();
return 0;
}