在 DICOM 文件上使用 GDCM 应用 LUT

Apply LUT using GDCM on DICOM File

我有一个具有 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 class,我可以正确显示图像。

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

你能告诉我如何正确使用 gdcm.LookupTable class 一次解码一帧吗?我使用的示例文件是 here.

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

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