magick++ colorspace confusion

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
kgob

magick++ colorspace confusion

Post by kgob »

I'm using image magick to read and write images and my own internal format for actual processing. Recently my images have come from different colorspaces (log, rec709, sRGB, and linear). I'd like to read in the file and then convert it into a linear space to be worked on. ImageMagick seems to have support for this but I haven't been able to make it work as I'd expect.

example : I want to tell image magick the file colorspace is sRGB so I get a good RGB back.

Code: Select all

Magick::Image img;
img.read( filename );
img.magick( "RGB" );
MagickCore::SetImageColorspace( img.image(), MagickCore::sRGBColorspace );
Magick::Blob blob; 
img.write( &blob );
What I get out of the blob is a "brighter" image than if I do not call SetImageColorspace, but I expected "darker". Obviously I'm new to working with colorspaces so I might have a significant misunderstanding of some concepts.

I am also trying to play with these functions to figure this out. Any help on where and when to use these would also be greatly appreciated.

Code: Select all

Magick::Image img;
img.colorSpace( MagickCore::ColorspaceType );
img.colorSpaceType( MagickCore::ColorspaceType );
MagickCore::RGBTransformImage( img.image(), MagickCore::sRGBColorspace );
MagickCore::SetImageColorspace( img.image(), MagickCore::RGBColorspace );
MagickCore::TransformColorspace( img.image(), MagickCore::sRGBColorspace );
MagickCore::TransformRGBImage( img.image(), MagickCore::Rec709LumaColorspace );
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: magick++ colorspace confusion

Post by magick »

Take a look at profile(). Call it twice. First to associate a profile with the image that describe the input colorspace, and again to transform the colorspace to the output colorspace.
kgob

Re: magick++ colorspace confusion

Post by kgob »

That looks interesting but I don't think it's what I'm looking for. Seems that the profile() is for color management for specific devices? So my monitor may come with a profile and I can use profile() to modify my colors do display correctly on this monitor... Is that right? profile() seems to support common profile types such as icc, icm etc.

But I think what I'm looking for are common profiles that images are stored in such as sRGB or rec709. Since MagickCore has these types enumerated in ColorspaceType (colorspace.h) I assume there is a way to use it without resorting to custom profile management.
kgob

Re: magick++ colorspace confusion

Post by kgob »

I've been looking at profile(). What blob am I supposed to pass into the profile( string, blob )? I've tried a few variations but nothing seems to work correctly. I downloaded "videohd.icc" which is supposed to be rec709 colorspace. Is this anywhere near correct? Should I be using the output blob of img.profile( "icc" )? I want the final blob in linear space.

Code: Select all

std::ifstream iccFile("videohd.icc", std::ios::in | std::ios::binary );
if( !iccFile.is_open() )return;
iccFile.seekg( 0, std::ios::end );
size_t filesize = iccFile.tellg();
iccFile.seekg( 0, std::ios::beg );
char *data = new char[filesize];
				
iccFile.read( data, filesize );
Magick::Blob iccBlob( data, filesize );
				
img.profile( "icc", iccBlob );
img.profile( "icc" );
                
img.magick( "RGB" );				
Magick::Blob blob;
img.write( &blob );
delete [] data;
Post Reply