rgb converted to grayscale by imagemagick

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

rgb converted to grayscale by imagemagick

Post by graemeNPS »

https://drive.google.com/folderview?id= ... sp=sharing

I have shared a folder with some sample files provided by our client.
Our client complains that some files converted by ImageMagick are converted to grayscale.
The samples.zip has the files they shared. The profilebroken.zip has files converted by IM (latest version, command line) that show the RGB source file converted to grayscale. The customer wants the files to convert RGB to RGB.
When I open the converted broken files in Photoshop, PS compains about a damaged profile. see profilecapture.png.
When PS displays the converted image, it shows as a gray image.

for my reference, our ticket number is:
TS-10381 ImageMagick conversion generates a Grayscale image not RGB

thanks,
Graeme
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rgb converted to grayscale by imagemagick

Post by fmw42 »

If the image has 3 identical channels, even if colorspace is RGB, IM by default will set the colorspace to Grayscale. However, in later versions of IM (6.9.2-1 or higher), you can override that behavior with a new -define colorspace:auto-grayscale=off. See http://www.imagemagick.org/script/comma ... php#define

try that and let us know if that works
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: rgb converted to grayscale by imagemagick

Post by graemeNPS »

Thanks, I will try this.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: rgb converted to grayscale by imagemagick

Post by graemeNPS »

Hi, your suggestion works fine on the command line.

But, I cannot get it working with 6.9.3.1 source and installer.

We build our ImageMagick components in visual studio 2010 MT dynamic mode Q16, and then run the IM installer to get the right bits on the customer machines.

When I build against 6.9.0.7 sources and run against the 6.9.0.7 installer, everything works, but we don't have the grayscale fix, so I am trying to upgrade to a later version.

I upgraded our build to 6.9.3.1 and ran the 6.9.3.1 installer, but then our code breaks using Magick::Image to get information from the file we are processing. We create the pointer to pImage, but when the method is finished there is a crash.

I am wondering if you know of any issues in using the latest. This also did not work for me with a 6.9.2 version of source and installer.

I have added ImageMagickAPIWrapper.GetFileInfo.txt.zip to the google drive location mentioned above to show what code we are calling.

Sorry I cannot tease out of our code a test executable to show the issue.

we have been using the workflow of building the source in visual studio and then install the release exe for these versions:
6.6.3
6.6.3-2-Q8

6.7.6
6.7.6-3-Q8

6.7.9
6.7.9-3_Q8

we switched to Q16 here:
6.8.9
6.8.9-1_Q16

6.8.9-3_Q16
6.8.9_3

6.9.0.7
6.9.0.7-Q16
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: rgb converted to grayscale by imagemagick

Post by graemeNPS »

I create and use a Magick::Image* thus:
Magick::Image * pImage = NULL;
try
{
pImage = new Magick::Image(lszOrgfilePath.c_str());
}
catch (...)
{
.. do some catchy stuff
return;
}
if(pImage)
{
do stuff with the pImage... get info such as colorspace etc.
}
//finish up
//delete pImage;
return;
}
this works with 9.6.3.1 only if I don't delete the pImage at the end of the method using it. And that leaks memory, of course. And that is new behaviour in this version. I get a crash if I do the correct thing:

//finish up
delete pImage;
return;
}
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: rgb converted to grayscale by imagemagick

Post by snibgo »

When I get a crash on correctly deleting an object, I eventually discover I've done something naughty with memory after creating the object, so something has become corrupted.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rgb converted to grayscale by imagemagick

Post by fmw42 »

I do not know how to declare -defines from the command line into your API. An Imagemagick developer will need to respond to that and to the crash issue on newer versions of IM.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: rgb converted to grayscale by imagemagick

Post by graemeNPS »

I recompiled everything with 6.9.3.1 and deployed the imagemagick installer on my test machine. Processing a 1000+ jpgs has resulted in memory filling up and a huge number of files in my windows temp dir, with name like magick_xxxxx, see examples below. None of this happens with 6.9.0.x version I was using (same code on my side, just a different IM version). I am wondering if the implementation of Magick::Image is leaking....

C:\Windows\Temp\magick-3884HzsEBXZgmMjB
C:\Windows\Temp\magick-3884I3UCCvOyINJA
C:\Windows\Temp\magick-3884Iahog8t4Jnq5
C:\Windows\Temp\magick-3884JSEuKWoa941c
C:\Windows\Temp\magick-3884K1qCJ1z-p5gF
C:\Windows\Temp\magick-3884KyCXWF3HnY07
C:\Windows\Temp\magick-3884N9M9eOpE7-GP
C:\Windows\Temp\magick-3884NsD6RvlZbPju
C:\Windows\Temp\magick-3884SeNWB6nNfD66
C:\Windows\Temp\magick-3884ii81C5cHdql1
C:\Windows\Temp\magick-3884j62H2c8gNagm
C:\Windows\Temp\magick-3884nlZSjNKkM7iY
C:\Windows\Temp\magick-3884ofh-IeJQjgeO
C:\Windows\Temp\magick-3884rWUxWXefzOUp
C:\Windows\Temp\magick-3884r_CoxRcf2PNT
C:\Windows\Temp\magick-3884sfDGmkCTV2O5
C:\Windows\Temp\magick-3884tSvuOs4lfyOM
C:\Windows\Temp\magick-3884u2MtArjKefMk
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: rgb converted to grayscale by imagemagick

Post by graemeNPS »

these temp files filled 14GB after processing about 1000 jpgs...
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: rgb converted to grayscale by imagemagick

Post by graemeNPS »

- seems they are generated after memory gets filled...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rgb converted to grayscale by imagemagick

Post by fmw42 »

Try changing your IM tmp directory to some place that has more space. See MAGICK_TEMPORARY_PATH at http://www.imagemagick.org/script/resou ... nvironment
Post Reply