java 生成 dicom uid,如何将元数据添加到图像(使用Java代码),然后将其转换为dicom...

I found a java code that converts a jpg and a Dicom(it takes the metadata fri¡om that one) files to a final Dicom one. What I want to do is convert the jpg image into a Dicom one, generating the metadata with java code.

BufferedImage jpg = ImageIO.read(new File("myjpg.jpg"));

// Convert the image to a byte array

DataBuffer buff = jpg.getData().getDataBuffer();

DataBufferUShort buffer = new DataBufferUShort(buff.getSize());

for (int i = 0; i < buffer.getSize(); ++i)

buffer.setElem(i, buff.getElem(i));

short[] data = buffer.getData();

ByteBuffer byteBuf = ByteBuffer.allocate(2 * data.length);

int i = 0;

while (data.length > i) {

byteBuf.putShort(data[i]);

i++;

}

// Copy a header

DicomInputStream dis = new DicomInputStream(new File("fileToCopyheaderFrom.dcm"));

Attributes meta = dis.readFileMetaInformation();

Attributes attribs = dis.readDataset(-1, Tag.PixelData);

dis.close();

// Change the rows and columns

attribs.setInt(Tag.Rows, VR.US, jpg.getHeight());

attribs.setInt(Tag.Columns, VR.US, jpg.getWidth());

System.out.println(byteBuf.array().length);

// Write the file

attribs.setBytes(Tag.PixelData, VR.OW, byteBuf.array());

DicomOutputStream dcmo = new DicomOutputStream(new File("myDicom.dcm"));

dcmo.writeFileMetaInformation(meta);

attribs.writeTo(dcmo);

dcmo.close();

解决方案

I am not expert in toolkit (and of-course Java as well).

Your "// Copy a header" section reads the source DICOM file and holds all the attributes in Attributes attribs variable.

Then, your "// Change the rows and columns" section modifies few attributes as per need.

Then, your "// Write the file" section simply add the attributes read from source file to destination file.

Now, you want to bypass the source DICOM file and convert plain JPEG to DICOM with adding attributes yourself.

Replace your "// Copy a header" section to build the instance of Attributes.

Attributes attribs = new Attributes();

attribs.setString(Tag.StudyDate, VR.DA, "20110404");

attribs.setString(Tag.StudyTime, VR.TM, "15");

The tags mentioned in above example are for example only. You have to decide yourself which tags you want to include. Note that specifications have defined Types 1, 1C, 2, 2C and 3 for tags depending on the SOP class you are dealing with.

While adding the tags, you have to take care of correct VR as well. Specifications talk about that thing as well.

I cannot explain all this here; too broad.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值