Reading 16-bit DICOM image does not work any more

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
paavo256
Posts: 3
Joined: 2012-07-26T05:16:43-07:00
Authentication code: 15

Reading 16-bit DICOM image does not work any more

Post by paavo256 »

It appears there is some version or platform difference in how ImageMagick handles 16-bit grayscale DICOM images. Our code has not changed; on Linux and Windows with ImageMagick 6.4.3 we get a 16-bit grayscale result, wherease on Mac with ImageMagick 6.7.8 we get an RGB (3x8bits) image (with apparently identic color channels). This means serious loss in the precision (16 bits->8 bits). Is it possible to somehow force the 16-bit grayscale output? Our code is using Magick++ and looks about like this:

Code: Select all

	
	Magick::Image image;
	image.read(filename.c_str());
	Magick::ImageType t = image.type();
	if (t==Magick::GrayscaleType || t==Magick::GrayscaleMatteType) {
		switch(image.depth()) {
			case 8:
				image.write(0, 0, w, h, "I", Magick::CharPixel, buffer);
				break;
			default:
				image.write(0, 0, w, h, "I", Magick::ShortPixel, buffer);
				break;
		}
	} else {
		image.write(0, 0, w, h, "BGR", Magick::CharPixel, buffer);
	}
TIA
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Reading 16-bit DICOM image does not work any more

Post by fmw42 »

I don't know much about DICOM or the changes you are seeing. Lots has changed since your first version. But you can try adding the command line equivalents of -depth 16 -type grayscale. What output image format are going to ? Sorry I do not know any API or the equivalent for them.
paavo256
Posts: 3
Joined: 2012-07-26T05:16:43-07:00
Authentication code: 15

Re: Reading 16-bit DICOM image does not work any more

Post by paavo256 »

fmw42 wrote:But you can try adding the command line equivalents of -depth 16 -type grayscale.
My problem is that this is some very general library code which has no idea what image it is reading, it might well be some color jpg or dicom or whatever. To be honest, I have no independent knowledge about the type of this particular DICOM image, I am just relying on the fact that the former ImageMagick repors the read-in image type as Magick::GrayscaleType and bit depth as 12.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Reading 16-bit DICOM image does not work any more

Post by fmw42 »

Perhaps you should provide a link to your DICOM image so that the IM developers can test with it.
paavo256
Posts: 3
Joined: 2012-07-26T05:16:43-07:00
Authentication code: 15

Re: Reading 16-bit DICOM image does not work any more

Post by paavo256 »

User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Reading 16-bit DICOM image does not work any more

Post by magick »

We can reproduce the problem you posted and have a patch. Look for it in ImageMagick 6.7.8-7 within a few days. Thanks.
Post Reply