We've been using ImageMagick successfully to convert dental X-Ray DICOM images into PNG for easier manipulation. So far so good.
However, we have some 16-bit grayscale RLE compressed DICOM images (written by LEADTOOLS software) (e.g. this one), that fail to convert correctly. What's more, certain 3rd party DICOM solutions also stumble over these images. The cause: endianness. LEADTOOLS writes LSB, while these other solutions assume MSB.
Our issue with the ImageMagick conversion is two fold:
- the resulting image is very dark
- the converted image contains 4 smaller versions of the source image
Code: Select all
static unsigned short ReadDCMLSBShort(DCMStreamInfo *stream_info,Image *image)
{
unsigned short
value;
if (image->compression != RLECompression)
return(ReadBlobLSBShort(image));
value=ReadDCMByte(stream_info,image) | (unsigned short)
(ReadDCMByte(stream_info,image) << 8);
return(value);
}
static unsigned short ReadDCMMSBShort(DCMStreamInfo *stream_info,Image *image)
{
unsigned short
value;
if (image->compression != RLECompression)
return(ReadBlobMSBShort(image));
value=(ReadDCMByte(stream_info,image) << 8) | (unsigned short)
ReadDCMByte(stream_info,image);
return(value);
}
Here follows snapshots of the sample image in its various forms.
The DICOM image actually looks like this:
Certain 3rd party solutions (e.g. Sante, and MicroDicom viewers) render this image thus:
Here is how ImageMagick converts it (pre-bug fix):
After the bug fix, the DICOM image is converted to this: