我有一个具有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
正确使用类一次解码一帧的正确方向?我使用的示例文件在这里。
更新:使用ImageRegionReader
适用于 8 位调色板颜色,但不适用于 16 位,您能检查一下原因吗?我这里有 16 位的示例。