【发布时间】: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 位调色板颜色。