某医院影像一直无法正常入库,经查看是影像文件做了jpeg无损压缩处理,于是想到了使用dcmtk做常规文件的装换,

1.首先编译dcmtk源码,此处有两项需要注意,一是开启动态链接库,二是关闭app的生成,可以加快编译


2.编译完之后安装到以下目录

头文件/usr/local/include/dcmtk

lib文件/usr/local/lib

然后在cd /etc/ld.so.conf.d/目录下新建一个动态库的加载配置文件dcmtk.conf

内容如下/opt/compress/lib

3.接下来编写解压缩程序

#include "dcmtk/ofstd/ofstream.h"
#include "dcmtk/dcmpstat/dvpsdef.h"    /* for constants */
#include "dcmtk/dcmpstat/dviface.h"    /* for DVInterface */
#include "dcmtk/ofstd/ofstring.h"   /* for OFString */
#include "dcmtk/ofstd/ofbmanip.h"   /* for OFBitmanipTemplate */
#include "dcmtk/ofstd/ofdatime.h"   /* for OFDateTime */
#include "dcmtk/dcmdata/dcuid.h"      /* for dcmtk version name */
#include "dcmtk/dcmdata/cmdlnarg.h"   /* for prepareCmdLineArgs */
#include "dcmtk/ofstd/ofconapp.h"   /* for OFConsoleApplication */
#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmpstat/dvpspr.h"
#include "dcmtk/dcmpstat/dvpssp.h"
#include "dcmtk/dcmpstat/dvpshlp.h"     /* for class DVPSHelper */
#include "dcmtk/ofstd/ofstd.h"
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcistrmf.h"
#include "dcmtk/dcmdata/libi2d/i2dbmps.h"
#include "dcmtk/dcmdata/dcpxitem.h"
#include "dcmtk/dcmjpeg/djdecode.h"
#include "dcmtk/dcmdata/dcvrfd.h"
#include "dcmtk/dcmjpeg/djencode.h"
#include "dcmtk/dcmjpeg/djrplol.h"
#include <iostream>
#include <string>  
int main(int argc,char *argv[])
{
    if(argc!=3){
        std::cout << "illegal parameters" << std::endl;
            return -1;
    }
    char* dcmPath= argv[1];
    char* compressPath = argv[2];

    DJDecoderRegistration::registerCodecs(); // register JPEG codecs
    DcmFileFormat fileformat;
    if (fileformat.loadFile(dcmPath).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(compressPath, EXS_LittleEndianExplicit);
      }
    }
    DJDecoderRegistration::cleanup();

    return 0 ;
}

3.编译程序

g++ uncompress.cpp -DHAVE_CONFIG_H -I/usr/local/include -L/usr/local/lib/ -pthread -lz -lcharls -lcmr -ldcmdata -ldcmdsig -ldcmfg -ldcmimage -ldcmimgle -ldcmiod -ldcmjpeg -ldcmjpls -ldcmnet -ldcmpmap -ldcmpstat -ldcmqrdb -ldcmrt -ldcmseg -ldcmsr -ldcmtls -ldcmtract -ldcmwlm -li2d -lijg12 -lijg16 -lijg8 -loflog -lofstd -o uncompress

4.运行并测试程序

./uncompress /opt/a.dcm /opt/b.dcm 其中a.dcm是待处理文件,b.dcm是处理后的文件