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

时间:2021-08-27 08:57:28

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.

我在DICOM图像的byte []中有一个原始像素数据。现在我想将这个byte []转换为Image对象。

I tried:

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

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

但这不适合我。我还应该使用什么?

7 个解决方案

#1


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. 从文件中识别PIXEL DATA标记。您可以使用FileStream逐字节读取。

  3. Read the pixel data
  4. 读取像素数据

  5. Convert it to RGB
  6. 将其转换为RGB

  7. Create a BitMap object from the RGB
  8. 从RGB创建BitMap对象

  9. Use Graphics class to draw the BitMap on a panel.
  10. 使用Graphics类在面板上绘制BitMap。

#2


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.

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

#3


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.

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

#4


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.

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

#5


You should use GDCM.

你应该使用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).

Grassroots DiCoM是DICOM医疗文件的C ++库。它自动包装到python / C#/ Java(使用swig)。它支持RAW,JPEG 8/12 / 16bits(有损/无损),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:

参见例如:

#6


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)

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

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?

另请注意,DICOM标准支持JPEG标准的几种变体。可能是Bitmap类不支持从DICOM文件获得的数据。你能写下转移语法吗?

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文件半年了。

#7


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.

DICOM是一个荒谬的规范,我真诚地希望它在不久的将来得到彻底改革。这就是说Offis有一个软件套件“DCMTK”,相当擅长用各种流行的编码转换dicoms。只是尝试在文件中跳过x字节可能对单个文件没问题,但如果你有一个卷或几个卷,则需要一个更健壮的策略。我使用了DCMTK的转换代码,只是在它们进入pnm之前抓取了图像位。您将在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是开源的,并附带相当简单的构建指令。

#1


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. 从文件中识别PIXEL DATA标记。您可以使用FileStream逐字节读取。

  3. Read the pixel data
  4. 读取像素数据

  5. Convert it to RGB
  6. 将其转换为RGB

  7. Create a BitMap object from the RGB
  8. 从RGB创建BitMap对象

  9. Use Graphics class to draw the BitMap on a panel.
  10. 使用Graphics类在面板上绘制BitMap。

#2


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.

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

#3


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.

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

#4


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.

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

#5


You should use GDCM.

你应该使用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).

Grassroots DiCoM是DICOM医疗文件的C ++库。它自动包装到python / C#/ Java(使用swig)。它支持RAW,JPEG 8/12 / 16bits(有损/无损),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:

参见例如:

#6


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)

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

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?

另请注意,DICOM标准支持JPEG标准的几种变体。可能是Bitmap类不支持从DICOM文件获得的数据。你能写下转移语法吗?

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文件半年了。

#7


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.

DICOM是一个荒谬的规范,我真诚地希望它在不久的将来得到彻底改革。这就是说Offis有一个软件套件“DCMTK”,相当擅长用各种流行的编码转换dicoms。只是尝试在文件中跳过x字节可能对单个文件没问题,但如果你有一个卷或几个卷,则需要一个更健壮的策略。我使用了DCMTK的转换代码,只是在它们进入pnm之前抓取了图像位。您将在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是开源的,并附带相当简单的构建指令。