Page 1 of 1

read() does not maintain depth

Posted: 2013-04-15T10:05:40-07:00
by personalrobert
Obviously I am relatively new to Magick++. I read in a 16-bit TIF file, but its depth prints as 8, and the resultant JPEG2000 file is also only 8 bpp. Can you tell me what I'm doing wrong? Thank you.

Version: ImageMagick 6.6.9-7 2012-08-17 Q16

Code: Select all

$ identify fullres.tif
fullres.tif TIFF 2560x3328 2560x3328+0+0 16-bit Grayscale DirectClass 5.893MB 0.000u 0:00.000

Code: Select all

#include <iostream>
#include <Magick++.h>

int main(int argc, char **argv)
{
    Magick::InitializeMagick(*argv);

    Magick::Image
        image;

    try
    {
        image.read("fullres.tif");
        std::cout << "Depth: " << image.depth() << std::endl;
        image.write("test.jp2");
    }
    catch(Magick::Exception &ex)
    {
        std::cerr << "Exception: " << ex.what() << std::endl;
    }
    return 0;
}

Code: Select all

$ identify test.jp2
test.jp2 JP2 2560x3328 2560x3328+0+0 8-bit DirectClass 519KB 0.380u 0:00.390

Re: read() does not maintain depth

Posted: 2013-04-15T11:23:21-07:00
by snibgo
Do you get the same result from a command?

Code: Select all

convert fullres.tif test.jp2
If so, I suspect the input file has only 8 or fewer significant bits of data. IM generally tries to shrink files when it can.

Your IM version is also very old.

Re: read() does not maintain depth

Posted: 2013-04-15T11:28:21-07:00
by personalrobert
No. When I run the command

Code: Select all

convert fullres.tif test.jp2
it generates a proper 16-bit JP2 file!

Re: read() does not maintain depth

Posted: 2013-04-15T11:44:13-07:00
by snibgo
Okay. Sorry, I can't help with Magic++. All I can suggest is upgrading to a more recent version. JP2 is a relatively new format, and IM v6.6.9 is very old.

Re: read() does not maintain depth

Posted: 2013-04-15T11:48:52-07:00
by personalrobert
6.6.9-7 is dated Aug 17, 2012. That may be "old", but "very old" is a stretch. :wink:

Re: read() does not maintain depth

Posted: 2013-04-15T12:12:28-07:00
by glennrp
personalrobert wrote:6.6.9-7 is dated Aug 17, 2012. That may be "old", but "very old" is a stretch. :wink:
That would probably be the date it was compiled on your platform. My copy of the source for 6.6.9-7 is from around the end of April 2011.
Somewhere between "old" and "very old".

Re: read() does not maintain depth

Posted: 2013-04-15T17:04:04-07:00
by personalrobert
I believe my problem is that the version of the Magick++ library I am using is 8-bit, and therefore the 16-bit image being read is converted to 8-bit when I call read(). Does this sound like a reasonable conclusion?

Re: read() does not maintain depth

Posted: 2013-04-15T17:26:03-07:00
by snibgo
You said it was "Version: ImageMagick 6.6.9-7 2012-08-17 Q16", which is 16-bit. But your library might be a different version, I suppose. If it is 8-bit, then all files it writes will be 8-bit.

Re: read() does not maintain depth

Posted: 2013-04-15T17:31:28-07:00
by personalrobert
The version output was from "convert -version", but Magick::Quantum is 1 (byte) and MaxRGB is 255, so I think you are right that my command line utilities are 16-bit and my library is 8.