【问题标题】:Apply LUT using GDCM on DICOM File在 DICOM 文件上使用 GDCM 应用 LUT
【发布时间】:2016-10-25 09:17:54
【问题描述】:

我有一个具有PALETTE_COLOR 光度解释的 RLE 压缩 DICOM 文件。使用 GDCM,我可以使用以下代码获取片段:

gdcm.ImageReader imagereader = new gdcm.ImageReader();
imagereader.SetFileName(fileName);
if (imagereader.Read())
  {
  DataElement compressedPixelData = imagereader.GetFile().GetDataSet().GetDataElement(Helper.PIXEL_DATA);
  SequenceOfFragments sf = compressedPixelData.GetSequenceOfFragments();
  if (sf == null) throw new Exception("Cannot get fragments!");
  Fragment frag = sf.GetFragment((uint)frameNumber);
  uint bufLen = Convert.ToUInt32(frag.GetByteValue().GetLength().toString());
  byte[] buffer = new byte[bufLen];
  frag.GetByteValue().GetBuffer(buffer, bufLen);
  }

现在我正在尝试从缓冲区创建图像。因为它是PALETTE_COLOR,所以我必须将 LUT 应用到缓冲区。我使用此代码:

gdcm.LookupTable lut = imagereader.GetImage().GetLUT();

int size = ImageWidth * ImageHeight * 3;
byte[] decodedBuffer = new byte[size];

bool worked = lut.Decode(decodedBuffer, (uint)size, buffer, (uint)bufLen);

if (worked)
   return decodedBuffer;
else
   return buffer;

decodedBuffer 的大小是Width * Height * 3,因为我希望在应用 LUT 后是 RGB 像素。但生成的图像不正确。

如果我使用ImageApplyLookupTable类,我可以正确显示图像。

我不想使用ImageApplyLookupTable 类,因为它会将整个图像(所有片段!)解码为原始 RGB 像素并消耗大量内存。我想逐帧解码以尽量减少内存使用。

您能否指出正确的方向,即如何正确使用gdcm.LookupTable 类一次解码一帧?我使用的示例文件是here.

更新:使用ImageRegionReader 可用于 8 位调色板颜色,但不适用于 16 位,您能检查一下原因吗?我有 16 位的示例 here

【问题讨论】:

  • @malat - 查看我的更新,它适用于 8 位,但不适用于 16 位,有什么线索吗?
  • 在上面给出的示例中,decodedBuffer 数组不正确。所有数组值都归零。我正在使用 8 位调色板颜色。

标签: c# dicom gdcm


【解决方案1】:

GDCM 附带了一堆示例,在您的情况下,我建议您开始阅读:ExtractImageRegionWithLUT.cs

代码非常愚蠢,因为它会在前一个帧上一遍又一遍地写入提取的帧。但无论如何,这应该给你基本的想法。这是我在这里所做的:

首先确保您的 C# 示例已构建(在我的案例中我使用 make):

$ make GDCMCSharpExample

然后:

$ ExtractImageRegionWithLUT.exe PAL-16_RLE.dcm

在 UNIX 上,这将创建一个原始文件,您可以使用 gdcmimg 将其转换回 DICOM:

$ gdcmimg --depth 16 --spp 3 --size 800,600 /tmp/frame_rgb.raw /tmp/frame_rgb.raw.dcm

然后您可以简单地查看它:

$ gdcmviewer /tmp/frame_rgb.raw.dcm

你甚至可以使用以下方法来说服自己:

$ gdcmimg -C 1.2.840.10008.5.1.4.1.1.3.1 --depth 16 --spp 3 --size 800,600 /tmp/frame_rgb.raw /tmp/frame_rgb.raw.dcm

【讨论】:

  • 对不起,它现在适用于 16 位。以前我忘记将值从 16 位重新计算为 24 位。我的查看器只支持 24 位。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多