【DICOM】解析并生成新的dcm文件以及在上面画图所遇到的坑

先用流程图简单阐述一下我遇到的实际情形。

Created with Raphaël 2.1.2 开始 解析dcm文件(非像素部分) 是否为压缩文件? 解压为非压缩的dcm文件 修改像素信息(画图),修改其他属性 写入相应的修改,生成新的dcm文件 结束 yes no
  1. 对已有dcm文件的解析。从而获取各个属性Attribute和相应的像素信息PixelData(也属于Attribute)
  2. 生成新的dcm文件。为什么要生成新的dcm文件? 肯定是在已有的dcm文件的基础上做了一些属性的修改,然后希望以新的dcm文件来体现这些修改。
  3. 画图。 这步属于在生成新的dcm文件之前的步骤,通过解析dcm文件属性获得pixelData然后对pixelData进行修改从而改变dcm图像外观。
  4. 解压 。dcm文件为了提高传输效率往往会进行压缩,然而医学图像的精准要求往往会进行无损压缩,这里主要针对的是无损压缩文件的解压问题。解压这步往往是在解析->画图->生成新的dcm文件之前。

该文建立在dcm4che-5.10.3的基础上。


解析属性(除了像素)

dicom协议以及dcm文件的组成网上有很多文章,这里就不再赘述。
大体你可以理解为一个dcm文件除了我们肉眼可见的图像以外还有很多属性(Attributes),这些属性有相应的tag(可以理解为int类型的key),类型(VR),值(value) 。 像素内容也是作为一个属性,存在最后面一个Attribute里。

        Attributes fmi;
        Attributes dataset;
        DicomInputStream dis = nulltry {
            dis = new DicomInputStream(src);
            fmi = dis.readFileMetaInformation();
            dis.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
            fmi.setString(Tag.MediaStorageSOPInstanceUID, VR.UI, instanceUID);
            dataset = dis.readDataset(-1, -1);     
        } catch (Exception e) {
            LOGGER.error("read intput dicom file error!!!", e);
            return false;
        }finally {
            SafeClose.close(dis);
        }   
        dataset.getValue(Tag.XXX);  // 获取某个属性 
        dataset.setValue(相应Tag, 该属性的vr, value); //存入某属性

以上建立在dcm4che的jar包基础上。

属性有很多种,比较重要的就是 图像所属序列的uid,图像自身的uid。以及传输语法 Transfer Syntax UID, 表明了该图像是以何种形式存储像素文件的(压缩与否,怎么压缩,显式VR隐式VR,bigEndian or Little Endian …)

Transfer Syntax UID Transfer Syntax name
1.2.840.10008.1.2 Implicit VR Endian: Default Transfer Syntax for DICOM
1.2.840.10008.1.2.1 Explicit VR Little Endian
1.2.840.10008.1.2.1.99 Deflated Explicit VR Little Endian
1.2.840.10008.1.2.2 Explicit VR Big Endian

Transfer Syntax UID Transfer Syntax name
1.2.840.10008.1.2.4.50 JPEG Baseline (Process 1):
Default Transfer Syntax for Lossy JPEG 8-bit Image Compression
1.2.840.10008.1.2.4.51 JPEG Baseline (Processes 2 & 4):
Default Transfer Syntax for Lossy JPEG 12-bit Image Compression
(Process 4 only)
1.2.840.10008.1.2.4.52 JPEG Extended (Processes 3 & 5) Retired
1.2.840.10008.1.2.4.53 JPEG Spectral Selection, Nonhierarchical (Processes 6 & 8) Retired
1.2.840.10008.1.2.4.54 JPEG Spectral Selection, Nonhierarchical (Processes 7 & 9) Retired
1.2.840.10008.1.2.4.55 JPEG Full Progression, Nonhierarchical (Processes 10 & 12) Retired
1.2.840.10008.1.2.4.56 JPEG Full Progression, Nonhierarchical (Processes 11 & 13) Retired
1.2.840.10008.1.2.4.57 JPEG Lossless, Nonhierarchical (Processes 14)
1.2.840.10008.1.2.4.58 JPEG Lossless, Nonhierarchical (Processes 15) Retired
1.2.840.10008.1.2.4.59 JPEG Extended, Hierarchical (Processes 16 & 18) Retired
1.2.840.10008.1.2.4.60 JPEG Extended, Hierarchical (Processes 17 & 19) Retired
1.2.840.10008.1.2.4.61 JPEG Spectral Selection, Hierarchical (Processes 20 & 22) Retired
1.2.840.10008.1.2.4.62 JPEG Spectral Selection, Hierarchical (Processes 21 & 23) Retired
1.2.840.10008.1.2.4.63 JPEG Full Progression, Hierarchical (Processes 24 & 26) Retired
1.2.840.10008.1.2.4.64 JPEG Full Progression, Hierarchical (Processes 25 & 27) Retired
1.2.840.10008.1.2.4.65 JPEG Lossless, Nonhierarchical (Process 28) Retired
1.2.840.10008.1.2.4.66 JPEG Lossless, Nonhierarchical (Process 29) Retired
1.2.840.10008.1.2.4.70 JPEG Lossless, Nonhierarchical, First- Order Prediction
(Processes 14 [Selection Value 1]):
Default Transfer Syntax for Lossless JPEG Image Compression
1.2.840.10008.1.2.4.80 JPEG-LS Lossless Image Compression
1.2.840.10008.1.2.4.81 JPEG-LS Lossy (Near- Lossless) Image Compression
1.2.840.10008.1.2.4.90 JPEG 2000 Image Compression (Lossless Only)
1.2.840.10008.1.2.4.91 JPEG 2000 Image Compression
1.2.840.10008.1.2.4.92 JPEG 2000 Part 2 Multicomponent Image Compression (Lossless Only)
1.2.840.10008.1.2.4.93 JPEG 2000 Part 2 Multicomponent Image Compression

Transfer Syntax UID Transfer Syntax name
1.2.840.10008.1.2.4.94 JPIP Referenced
1.2.840.10008.1.2.4.95 JPIP Referenced Deflate
1.2.840.10008.1.2.5 RLE Lossless
1.2.840.10008.1.2.6.1 RFC 2557 MIME Encapsulation

Transfer Syntax UID Transfer Syntax name
1.2.840.10008.1.2.4.100 MPEG2 Main Profile Main Level
1.2.840.10008.1.2.4.102 MPEG-4 AVC/H.264 High Profile / Level 4.1
1.2.840.10008.1.2.4.103 MPEG-4 AVC/H.264 BD-compatible High Profile / Level 4.1

目前该贴实际情况只需要了解 ‘1.2.840.10008.1.2’ 默认格式 和 ‘1.2.840.10008.1.2.4.70’ jpeg 无损压缩格式。

参考:

http://samucs.blogspot.com/2008/09/processing-dicom-images-using-dcm4che-2.html

https://github.com/haraldk/TwelveMonkeys/issues/47

你可能感兴趣的:(图形,DICOM)