简体   繁体   English

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

[英]How to create an image from a raw data of DICOM image

I have a raw pixel data in a byte[] from a DICOM image. 我有来自DICOM图像的byte[]的原始像素数据。 Now I would like to convert this byte[] to an Image object. 现在,我想将此byte[]转换为Image对象。

I tried: 我试过了:

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

but this is not working for me. 但这对我不起作用。 What else should I be using ? 我还应该使用什么?

One thing to be aware of is that a dicom "image" is not necessarily just image data. 要注意的一件事是,dicom“图像”不一定只是图像数据。 The dicom file format contains much more than raw image data. dicom文件格式包含的内容远远超出原始图像数据。 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. 考虑检查dicom文件标准,您应该能够在Wikipedia文章上找到dicom的链接。 This should help you figure out how to parse out the information you're actually interested in. 这应该可以帮助您弄清楚如何解析您实际感兴趣的信息。

You should use GDCM. 您应该使用GDCM。

Grassroots DiCoM is a C++ library for DICOM medical files. 草根DiCoM是用于DICOM医疗文件的C ++库。 It is automatically wrapped to python/C#/Java (using swig). 它会自动包装到python / C#/ Java(使用swig)。 It supports RAW, JPEG 8/12/16bits (lossy/lossless), JPEG 2000, JPEG-LS, RLE and deflated (zlib). 它支持RAW,JPEG 8/12/16位(有损/无损),JPEG 2000,JPEG-LS,RLE和放气(zlib)。

It is portable and is known to run on most system (Win32, linux, MacOSX). 它是可移植的,并且已知可以在大多数系统(Win32,Linux,MacOSX)上运行。

See for example: 参见例如:

The pixel data usually (if not always) ends up at the end of the DICOM data. 像素数据通常(如果不是始终)以DICOM数据结尾。 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. 如果您可以弄清楚宽度,高度,步幅和颜色深度,则应该可以跳到(7FE0,0010)数据元素值,而只是获取后续字节。 This is the trick that most normal image viewers use when they show DICOM images. 这是大多数普通图像查看器在显示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. 有一个名为EvilDicom( http://rexcardan.com/evildicom/ )的C#库,可用于将图像从DICOM文件中拉出。 It has a tutorial on how to do it on the website. 它在网站上提供了有关如何操作的教程。

You have to do the following 您必须执行以下操作

  1. Identify the PIXEL DATA tag from the file. 从文件中识别PIXEL DATA标签。 You may use FileStream to read byte by byte. 您可以使用FileStream逐字节读取。
  2. Read the pixel data 读取像素数据
  3. Convert it to RGB 转换为RGB
  4. Create a BitMap object from the RGB 从RGB创建一个BitMap对象
  5. Use Graphics class to draw the BitMap on a panel. 使用Graphics类在面板上绘制BitMap。

DICOM is a ridiculous specification and I sincerely hope it gets overhauled in the near future. DICOM是一个荒谬的规范,我衷心希望它会在不久的将来得到彻底修改。 That said Offis has a software suite "DCMTK" which is fairly good at converting dicoms with the various popular encodings. 也就是说,Offis拥有一个软件套件“ DCMTK”,该套件非常擅长用各种流行的编码转换dicom。 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. 仅尝试跳过文件的x字节可能对于单个文件来说会很好,但是如果您有一个或多个卷,则可以采用更可靠的策略。 I used DCMTK's conversion code and just grabbed the image bits before they went into a pnm. 我使用了DCMTK的转换代码,只是在图像位进入pnm之前就对其进行了抓取。 The file you'll be looking for in DCMTK is dcm2pnm or possibly dcmj2pnm depending on the encoding scheme. 您将在DCMTK中寻找的文件是dcm2pnm或可能是dcmj2pnm,具体取决于编码方案。

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. DCMTK是开源的,并带有相当简单的构建说明。

Are you working with a pure standard DICOM File? 您正在使用纯标准的 DICOM文件吗? 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) . 我一直在维护DICOM解析器两年多了,但遇到了一些真正的奇怪DICOM文件,这些文件并没有完全满足标准(公司实现了“自己的”扭曲标准DICOM文件)。 flush you byte array into a file and test whether your image viewer(irfanview, picassa or whatever) can show it. 将字节数组刷新到文件中,然后测试图像查看器(irfanview,picassa或其他任何对象)是否可以显示它。 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) 如果您的代码使用的是正常的JPEG流,那么根据我的经验,有99.9999%的机会是因为文件以某种奇怪的方式破坏了标准(并且相信我,医疗公司做了很多事情)

Also note that DICOM standard support several variants of the JPEG standard . 另请注意,DICOM标准支持JPEG标准的多种变体。 could be that the Bitmap class doesn't support the data you get from the DICOM file. 可能是Bitmap类不支持您从DICOM文件获取的数据。 Can you please write down the transfer syntax? 您能写下传输语法吗?

You are welcome to send me the file (if it's not big) yossi1981@gmail.com , I can check it out , There was a time I've been hex-editing DICOM file for a half a year. 欢迎您将文件发送给我(如果不大)yossi1981@gmail.com,我可以检查一下,有一段时间我一直在对DICOM文件进行十六进制编辑。

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

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