I have an RLE compressed DICOM file that has PALETTE_COLOR
photometric interpretation. Using GDCM, I can get the fragment using this code:
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);
}
Now I'm trying to create an image from the buffer. Since it's PALETTE_COLOR
, I have to apply the LUT to the buffer. I use this code :
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;
The decodedBuffer size is Width * Height * 3
since I expect RGB pixel after applying LUT. But the resulting image is incorrect.
If I use ImageApplyLookupTable
class, I can display the image correctly.
I don't want to use ImageApplyLookupTable
class since it will decode the entire image (all fragments!) into raw RGB pixels and consume a lot of memory. I want to decode framge by frame to minimize memory usage.
Could you point me to right direction on how to use gdcm.LookupTable
class correctly to decode a frame at a time ? The sample file I used is here.
UPDATED: Using ImageRegionReader
worked for the 8 bit PALETTE COLOR, but didn't work for 16 bit, could you check why? I have the sample here for 16 bit.