【问题标题】:how I can write more than one jpg image to Dicom file Using Dcm4che3?如何使用 Dcm4che3 将多个 jpg 图像写入 Dicom 文件?
【发布时间】:2014-01-26 21:55:50
【问题描述】:

在前一段时间我问过的上一个问题中,我可以将一个图像写入 Dicom,但现在我需要在 Dicon 文件中以帧的顺序写入两个或多个 jpg 图像。使用 dcm4che3。请有人帮忙吗?

public static void main(String[] args) throws Exception {
    Attributes attrs = new Attributes();
    String ts = UID.JPEG2000;
    Attributes fmi = Attributes.createFileMetaInformation("1.2.3", UID.MRImageStorage , ts);
    File f = new File("/tmp/taylor.jpg");
    BufferedImage vf = ImageIO.read(f);
    attrs.setString(Tag.PatientName, VR.AE, "Test");
    attrs.setString(Tag.PatientSex, VR.CS, "M");
    attrs.setString(Tag.PatientID, VR.CS, "10");
    attrs.setString(Tag.PatientBirthDate, VR.AS, "19861010");
    attrs.setString(Tag.StudyDate, VR.AS, "20140126");
    attrs.setString(Tag.SeriesDate, VR.AS, "20140126");
    attrs.setString(Tag.StudyTime, VR.AS, "101010");
    attrs.setString(Tag.SeriesTime, VR.AS, "101010");
    attrs.setString(Tag.StudyDescription, VR.AS, "Test #1");
    attrs.setString(Tag.SeriesDescription, VR.AS, "Test #2");
    attrs.setString(Tag.Modality, VR.CS, "MR");
    attrs.setInt(Tag.Columns, VR.US, vf.getWidth());
    attrs.setInt(Tag.Rows, VR.US, vf.getHeight());
    attrs.setInt(Tag.InstanceNumber, VR.US, 1);
    attrs.setInt(Tag.SamplesPerPixel, VR.IS, 3);
    attrs.setString(Tag.PhotometricInterpretation, VR.CS, "MONOCHROME2");
    attrs.setInt(Tag.BitsAllocated, VR.IS, 8);
    attrs.setInt(Tag.BitsStored, VR.IS, 8);
    attrs.setInt(Tag.NumberOfFrames, VR.IS, 5);
    attrs.setInt(Tag.SeriesNumber, VR.IS, 2);


    DataBufferByte buff = (DataBufferByte) vf.getData().getDataBuffer();
    Fragments fr = attrs.newFragments(Tag.PixelData, VR.OW, 1);
    for (int i = 0; i < 5; i++) {
        fr.add(buff.getData(0));
    }
    attrs.trimToSize();
    File fi = new File("/tmp/test.dcm");
    System.out.println(fi.getCanonicalPath());
    System.out.println(fmi);
    System.out.println(attrs);
    DicomOutputStream dos = new DicomOutputStream(fi);
    dos.writeDataset(fmi, attrs);
    dos.finish();
    dos.close();
}

此代码用于创建 dcm 文件,但我无法使用 Wea​​sis 查看器打开它。

【问题讨论】:

    标签: java dicom


    【解决方案1】:

    使用我给你的previously,你将遍历所有 jpg 图像并将字节连接在一起。将连接的字节设置为像素数据。

    然后添加

     attribs.setInt(Tag.NumberOFFrames, VR.**, numberOfImages);
    

    到 dicom 标头。我不记得这个标签的 VR 应该是什么,所以检查一下 DICOM 标准。

    编辑 1

    我会将像素数据设置为

        byte[] buffbytes = buff.getData(0);
        byte[] b = new byte[5*buff.getData(0).length];
        for (int i = 0; i < 5; i++) {
            System.arraycopy(buffbytes, 0, b, i*buffbytes.length, buffbytes.length);
        }
    
        attrs.setBytes(Tag.PixelData, VR.OW, b);
    

    【讨论】:

    • 再次感谢您的帮助,我尝试了您的建议,但是我得到了 java.io.EOFException ,您自己尝试了吗?
    • 我以前做过很多次类似的事情。你能在你的问题中发布你的代码吗?
    • 我在线程 "main" java.lang.IllegalArgumentException: Raster ByteInterleavedRaster: width = 1177 height = 995 #numDataElements 3 dataOff[0] = 0 is in compatible with ColorModel ColorModel: #pixelBits = 8 numComponents = 1 颜色空间 = java.awt.color.ICC_ColorSpace@142ea9b 透明度 = 1 有 alpha = false isAlphaPre = false
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    相关资源
    最近更新 更多