如何从 DICOM 图像的原始数据创建图像

发布于 2024-07-16 13:36:23 字数 237 浏览 5 评论 0原文

我有来自 DICOM 图像的 byte[] 原始像素数据。 现在我想将此 byte[] 转换为 Image 对象。

我尝试过:

Image img = Image.FromStream(new MemoryStream(byteArray));

但这对我不起作用。 我还应该使用什么?

I have a raw pixel data in a byte[] from a DICOM image.
Now I would like to convert this byte[] to an Image object.

I tried:

Image img = Image.FromStream(new MemoryStream(byteArray));

but this is not working for me. What else should I be using ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

屌丝范 2024-07-23 13:36:23

需要注意的一件事是,dicom“图像”不一定只是图像数据。 dicom 文件格式包含的不仅仅是原始图像数据。 这可能就是你被挂断的地方。 考虑查看 dicom 文件标准,您应该能够在 dicom 的维基百科文章上找到链接。 这应该可以帮助您弄清楚如何解析出您真正感兴趣的信息。

One thing to be aware of is that a dicom "image" is not necessarily just image data. The dicom file format contains much more than raw image data. This may be where you're getting hung up. Consider checking out the dicom file standard which you should be able to find linked on the wikipedia article for dicom. This should help you figure out how to parse out the information you're actually interested in.

苏佲洛 2024-07-23 13:36:23

您必须执行以下操作

  1. 从文件中识别像素数据标签。 您可以使用 FileStream 逐字节读取。
  2. 读取像素数据
  3. 将其转换为 RGB
  4. 从 RGB 创建 BitMap 对象
  5. 使用 Graphics 类在面板上绘制 BitMap。

You have to do the following

  1. Identify the PIXEL DATA tag from the file. You may use FileStream to read byte by byte.
  2. Read the pixel data
  3. Convert it to RGB
  4. Create a BitMap object from the RGB
  5. Use Graphics class to draw the BitMap on a panel.
银河中√捞星星 2024-07-23 13:36:23

像素数据通常(如果不是总是)出现在 DICOM 数据的末尾。 如果您可以计算出宽度、高度、步幅和颜色深度,则应该可以跳到 (7FE0,0010) 数据元素值并仅获取后续字节。 这是大多数普通图像查看器在显示 DICOM 图像时使用的技巧。

The pixel data usually (if not always) ends up at the end of the DICOM data. If you can figure out width, height, stride and color depth, it should be doable to skip to the (7FE0,0010) data element value and just grab the succeeding bytes. This is the trick that most normal image viewers use when they show DICOM images.

青朷 2024-07-23 13:36:23

有一个名为 EvilDicom (http://rexcardan.com/evildicom/) 的 C# 库,可用于从 DICOM 文件中提取图像。 它在网站上有一个关于如何操作的教程。

There is a C# library called EvilDicom (http://rexcardan.com/evildicom/) that can be used to pull the image out of a DICOM file. It has a tutorial on how to do it on the website.

梦在深巷 2024-07-23 13:36:23

您应该使用 GDCM。

Grassroots DiCoM 是一个用于 DICOM 医疗文件的 C++ 库。 它会自动包装为 python/C#/Java(使用 swig)。 它支持 RAW、JPEG 8/12/16 位(有损/无损)、JPEG 2000、JPEG-LS、RLE 和 deflated (zlib)。

它是可移植的,并且可以在大多数系统(Win32、linux、MacOSX)上运行。

例如参见:

You should use GDCM.

Grassroots DiCoM is a C++ library for DICOM medical files. It is automatically wrapped to python/C#/Java (using swig). It supports RAW, JPEG 8/12/16bits (lossy/lossless), JPEG 2000, JPEG-LS, RLE and deflated (zlib).

It is portable and is known to run on most system (Win32, linux, MacOSX).

See for example:

情魔剑神 2024-07-23 13:36:23

您使用的是纯标准 DICOM 文件吗? 我维护 DICOM 解析器已有两年多了,我遇到了一些非常奇怪的 DICOM 文件,它们没有完全满足标准(公司实现了他们的“自己的”扭曲的标准 DICOM 文件)。 将字节数组刷新到文件中并测试您的图像查看器(irfanview、picassa 或其他)是否可以显示它。 如果您的代码使用普通的 JPEG 流,那么根据我的经验,99.9999% 的可能性只是因为该文件以某种奇怪的方式违反了标准(相信我,医疗公司经常这样做)

还要注意,DICOM 标准支持多种JPEG 标准的变体。 可能是 Bitmap 类不支持从 DICOM 文件获取的数据。 你能写下传输语法吗?

欢迎您将文件发送给我(如果文件不大)[电子邮件受保护],我可以查一下,曾经有一段时间我对DICOM文件进行了半年的十六进制编辑。

Are you working with a pure standard DICOM File? I've been maintainning a DICOM parser for over a two years and I came across some realy strange DICOM files that didn't completely fulfill the standard (companies implementing their "own" twisted standard DICOM files) . flush you byte array into a file and test whether your image viewer(irfanview, picassa or whatever) can show it. If your code is working with a normal JPEG stream then from my experience , 99.9999% chance that this simply because the file voilate the standard in some strange way ( and believe me , medical companies does that a lot)

Also note that DICOM standard support several variants of the JPEG standard . could be that the Bitmap class doesn't support the data you get from the DICOM file. Can you please write down the transfer syntax?

You are welcome to send me the file (if it's not big) [email protected] , I can check it out , There was a time I've been hex-editing DICOM file for a half a year.

‘画卷フ 2024-07-23 13:36:23

DICOM 是一个荒谬的规范,我真诚地希望它在不久的将来得到彻底修改。 也就是说,Offis 有一个软件套件“DCMTK”,它非常擅长用各种流行的编码转换 dicom。 对于单个文件来说,尝试在文件中向前跳过 x 字节可能没问题,但如果您有一个卷或多个卷,则需要更强大的策略。 我使用 DCMTK 的转换代码,并在图像位进入 pnm 之前抓取图像位。 您将在 DCMTK 中查找的文件是 dcm2pnm 或可能是 dcmj2pnm,具体取决于编码方案。

我遇到了缩放窗口问题,我用运行时标志之一修复了该问题。 DCMTK 是开源的,并附带相当简单的构建指令。

DICOM is a ridiculous specification and I sincerely hope it gets overhauled in the near future. That said Offis has a software suite "DCMTK" which is fairly good at converting dicoms with the various popular encodings. Just trying to skip ahead in the file x-bytes will probably be fine for a single file but if you have a volume or several volumes a more robust strategy is in order. I used DCMTK's conversion code and just grabbed the image bits before they went into a pnm. The file you'll be looking for in DCMTK is dcm2pnm or possibly dcmj2pnm depending on the encoding scheme.

I had a problem with the scale window that I fixed with one of the runtime flags. DCMTK is open source and comes with fairly simple build instructions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文