简体   繁体   English

如何使用 dcmtk 从现有的 opencv Mat 图像创建 DICOM 文件?

[英]How can I create a DICOM file from a existing opencv Mat image using dcmtk?

I am new to DICOM and dcmtk.我是 DICOM 和 dcmtk 的新手。

I use dcmtk to read a DICOM image and convert it to a opencv Mat.我使用 dcmtk 读取 DICOM 图像并将其转换为 opencv Mat。 Then do some processing by opencv. Now I want to save the processed image back to DICOM image.然后通过opencv做一些处理。现在我想将处理后的图像保存回DICOM图像。 But I don't know how to create a DICOM file from a opencv Mat (I only need the pixel data).但我不知道如何从 opencv Mat 创建 DICOM 文件(我只需要像素数据)。

I just change the pixel values to do some denoising.我只是改变像素值来做一些去噪。 Bit depth, resolution and other information stay the same.位深度、分辨率和其他信息保持不变。

I am using simple X-Ray images of SMT or other objects in DICOM format.我正在使用 DICOM 格式的 SMT 或其他对象的简单 X 射线图像。

Could anyone tell me how to do it with opencv, c++ and dcmtk.谁能告诉我如何使用 opencv、c++ 和 dcmtk 来做到这一点。

My goal is to Generate a image(DICOM file) with the same pixel data as existing Mat in the specified directory.我的目标是生成具有与指定目录中现有 Mat 相同像素数据的图像(DICOM 文件)。 If possible, please show me some code.如果可能的话,请给我一些代码。

DICOM has the concept of IODs (Information Object Definitions) which is a bit hard to grasp for beginners. DICOM 有 IOD(信息 Object 定义)的概念,对于初学者来说有点难以掌握。 With your comments that everything about the pixel format remains constant, and you are just improving the image quality, I would propose that you copy the original image and save a modified version of it back (to a different filename) rather than creating a new image from scratch.根据您的评论,关于像素格式的一切都保持不变,而您只是在提高图像质量,我建议您复制原始图像并将其修改后的版本保存回去(以不同的文件名),而不是创建新图像从头开始。

To conform to DICOM, you will have to change a few more attributes in the modified copy of your original image:为了符合 DICOM,您必须在原始图像的修改副本中更改更多属性:

  • Create a new SOP Instance UID using DcmGenerateUniqueIdentifier使用 DcmGenerateUniqueIdentifier 创建新的 SOP 实例 UID
  • Set the image type (0008,0008) DERIVED\SECONDARY设置图像类型 (0008,0008) DERIVED\SECONDARY
  • Change all timestamps in the image that refer to the creation of the image (eg Content Date (0008,0023) and Content Time (0008,0033)更改图像中涉及图像创建的所有时间戳(例如内容日期 (0008,0023) 和内容时间 (0008,0033)

Ideally, you would also:理想情况下,您还将:

  • add a Derivation Description (0008,2111)添加推导说明 (0008,2111)
  • Reference the source image in the Referenced Image Sequence (0008,1140) to tell which original acquisition data was the basis for your derived image参考参考图像序列 (0008,1140) 中的源图像,以判断哪些原始采集数据是派生图像的基础
  • Assign a new Series Instance UID (0020,000E), Series Number (0020,0011) and SeriesDescription (0008,103E) -> This makes sure that the improved images will appear in a separate "folder"分配一个新的系列实例 UID (0020,000E)、系列编号 (0020,0011) 和系列描述 (0008,103E) -> 这确保改进后的图像将出现在单独的“文件夹”中

Sorry for being too lazy to write the code for you.抱歉懒得给你写代码了。 But in the sources of the Dcmtk samples you will find a plethora of references that show how to do these modifications.但在 Dcmtk 示例的源代码中,您会发现大量参考资料,这些参考资料展示了如何进行这些修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM