在我之前问过的问题中,我可以将一个图像写到Dicom,但是现在我需要在Dicon file.Using dcm4che3中以序列的形式以两个或更多的jpg图像作为序列,请有人帮忙吗?
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文件,但我无法用Weasis查看器打开它。
发布于 2014-01-23 09:13:52
使用我给您的previously,您将遍历所有jpg图像,并将字节连接在一起。将级联的字节设置为像素数据。
然后添加
attribs.setInt(Tag.NumberOFFrames, VR.**, numberOfImages);到。我不记得这个标签的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);https://stackoverflow.com/questions/21255783
复制相似问题