DICOM DCM4CHE影像压缩

随着医疗影像的发展,影像设备拍摄的图像越来越大,越来越多,但医疗影像的存储成本是很高的(云存储就更不用说了),所以在存储的时候会先将医疗影像压缩,之后再存储,以节省存储成本,所以着手研究DCM压缩和解压…

  1. 什么是传输语义

在进行无损压缩的主题之前,先说一下什么是传输语义吧!毕竟是否进行压缩最直接的观察点就在传输语义;
点击了解传出语义
DICOM DCM4CHE影像压缩_第1张图片
主要知道 **1.2.840.10008.1.2.4.70(JPEGLossless)1.2.840.10008.1.2.4.90(JPEG2000LosslessOnly)**是无损压缩就好

  1. 直接上代码

所需maven如下:

 <!--dcm4che-->
        <dependency>
            <groupId>org.dcm4che</groupId>
            <artifactId>dcm4che-core</artifactId>
            <version>5.16.1</version>
        </dependency>
        <dependency>
            <groupId>org.dcm4che</groupId>
            <artifactId>dcm4che-image</artifactId>
            <version>5.16.1</version>
        </dependency>
        <dependency>
            <groupId>org.dcm4che</groupId>
            <artifactId>dcm4che-imageio</artifactId>
            <version>5.16.1</version>
        </dependency>
        <dependency>
            <groupId>org.dcm4che</groupId>
            <artifactId>dcm4che-imageio-opencv</artifactId>
            <version>5.16.1</version>
        </dependency>
        <dependency>
            <groupId>org.weasis.opencv</groupId>
            <artifactId>weasis-opencv-core</artifactId>
            <version>3.0.4</version>
        </dependency>

代码如下:

package com.mpx.util;
 
import org.dcm4che3.data.Attributes;
import org.dcm4che3.util.Property;
import org.dcm4che3.imageio.codec.Transcoder;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
 
public class Dcm2Dcm2 {
 
 
    private static List<Property> params = new ArrayList<Property>();
 
    public static void main(String[] args) {
        File src = new File("F:\Desktop\2238\DX\src.DCM"); //带有压缩协议的dicom原始文件
        File dest = new File("F:\Desktop\2238\DX\des1.2.840.10008.1.2.4.90.DCM"); //压缩成无损压缩的dicom目标文件
        try {
            transcodeWithTranscoder(src, dest);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    public static void transcodeWithTranscoder(File src, final File dest) throws IOException {
        try (Transcoder transcoder = new Transcoder(src)) {
            transcoder.setIncludeFileMetaInformation(true);
            transcoder.setDestinationTransferSyntax("1.2.840.10008.1.2.4.90");
            Property p = new Property("compressionQuality", 0.5);//压缩率
            params.add(p);
            transcoder.setCompressParams(params.toArray(new Property[params.size()]));
            transcoder.transcode(new Transcoder.Handler() {
                @Override
                public OutputStream newOutputStream(Transcoder transcoder, Attributes dataset) throws IOException {
                    return new FileOutputStream(dest);
                }
            });
        } catch (Exception e) {
            Files.deleteIfExists(dest.toPath());
            throw e;
        }
    }
 
}

看一下压缩的效果
DICOM DCM4CHE影像压缩_第2张图片

其实上面有一行代码 引起了我的注意

Property p = new Property("compressionQuality", 0.5);//压缩率

难道我可以控制压缩的率的大小?
随后我修改成

Property p = new Property("compressionQuality", 0.1);//压缩率

想着可以压缩的更小一点

结果呢~一样
DICOM DCM4CHE影像压缩_第3张图片
后面果断尝试把这段注释了

Property p = new Property("compressionQuality", 0.5);//压缩率
            params.add(p);
            transcoder.setCompressParams(params.toArray(new Property[params.size()]));

结果奇迹出现了 2927kb 成了819kb
DICOM DCM4CHE影像压缩_第4张图片

你可能感兴趣的:(DCM4CHE)