Color issue when using composite

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
caliguian
Posts: 33
Joined: 2012-08-10T12:15:13-07:00
Authentication code: 67789

Color issue when using composite

Post by caliguian »

This may or may not be a bug, but I am having a really hard time getting it figured out if it is not a bug. Here is what is happening:

I have a fairly normal jpg image, and a smaller png image. I am using the png image as a watermark on the larger jpg image, and I am using composite -dissolve to do it. Here is the code that I am using to add the watermark:
composite -dissolve 40 -geometry +3+3 -gravity NorthWest 'watermarkFile.png' 'original.jpg' 'composite.jpg'

For most images that works just fine and the composite image comes out looking great, but for some of the jpg images (Black & White images, it seems) the composite image seems extremely blown out and the image is much brighter than it should be.

My version of ImageMagick says: Version: ImageMagick 6.7.8-6 2012-08-09 Q16 http://www.imagemagick.org

I just updated ImageMagick yesterday and before that I didn't notice this problem, so it may have to do with the version of ImageMagick I am using. Or I may have just not noticed it before now.

Example files to test with are:
http://instaproofs.com/temp/exampleImag ... iginal.jpg
http://instaproofs.com/temp/exampleImag ... rkFile.png

Resulting image:
http://instaproofs.com/temp/exampleImag ... posite.jpg

Any help would be appreciated!

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

Re: Color issue when using composite

Post by fmw42 »

After IM 6.7.8.3 grayscale images became linear rather than non-linear sRGB. Thus to reproduce your results, you need to use the more current syntax of convert rather than composite and add -set colorspace sRGB so that the output won't be determined by the grayscale image.

Try this, which works on my IM 6.7.8.9

convert original.jpg watermarkFile.png -set colorspace sRGB -gravity northwest -geometry +3+3 \
-define compose:args=40,100 -compose dissolve -composite test.jpg

This issue makes composite almost useless these days.
caliguian
Posts: 33
Joined: 2012-08-10T12:15:13-07:00
Authentication code: 67789

Re: Color issue when using composite

Post by caliguian »

You rock! That seems to work great for putting the watermarks on without messing up the colors.

I have another issue that seems like it may be related to this change as well. Mind taking a look at it too? Here are the details:

As a part of my image processing process I convert a lot of images from color to B&W (Grayscale). After upgrading imagemagick yesterday a lot of my B&W conversions were coming out very very dark, so I got on the forums and read about having to put "-colorspace sRGB" into the convert command for Grayscale images. So I added that in, and while it did seem to work for *some* of my images, it did not work for all of them. Some come out nice and pretty and retain all of their details, and others are continuing to come out very very dark.

Here is a file that came out nice and pretty:
Original: http://instaproofs.com/temp/exampleImag ... iginal.jpg
Converted to B&W: http://instaproofs.com/temp/exampleImag ... _black.jpg

Here is a file that is coming out very dark:
Original: http://instaproofs.com/temp/exampleImag ... iginal.jpg
Converted to B&W: http://instaproofs.com/temp/exampleImag ... _black.jpg

The script I am using to convert the image is as follows (I am also resizing the image in the same script):
convert -size {width}x{height} original.jpg -resize {width}x{height} +profile "*" -colorspace Gray -colorspace sRGB 'black.jpg'

Is there a new way to convert images to grayscale as well? It has been 5 or 6 years since I wrote the original script, so I may just be doing things the old fashioned way.
Last edited by caliguian on 2012-08-10T22:27:13-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color issue when using composite

Post by fmw42 »

For processing images to grayscale, put -set colorspace RGB before -colorspace gray to keep the old look.

convert image -set colorspace RGB -colorspace gray result
caliguian
Posts: 33
Joined: 2012-08-10T12:15:13-07:00
Authentication code: 67789

Re: Color issue when using composite

Post by caliguian »

fmw42 wrote:For processing images to grayscale, put -set colorspace RGB before -colorspace gray to keep the old look.

convert image -set colorspace RGB -colorspace gray result
Thanks for the response!

After trying your suggestion, the results seem to be identical for both "-set colorspace RGB -colorspace gray" and "-colorspace Gray -colorspace sRGB." Is the "-set colorspace RGB -colorspace gray" syntax more correct, or is it just a different way to do the same thing?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color issue when using composite

Post by fmw42 »

caliguian wrote:
fmw42 wrote:For processing images to grayscale, put -set colorspace RGB before -colorspace gray to keep the old look.

convert image -set colorspace RGB -colorspace gray result
Thanks for the response!

After trying your suggestion, the results seem to be identical for both "-set colorspace RGB -colorspace gray" and "-colorspace Gray -colorspace sRGB." Is the "-set colorspace RGB -colorspace gray" syntax more correct, or is it just a different way to do the same thing?

I get two different results from those commands on IM 6.7.8.9 using the zelda image.

Image

My way, makes the image non-linear but still gray with gamma=1. The second way, converts the image to linear gray and then converts it to sRGB (not grayscale), with a gamma=0.4545.

Look at your resulting images with identify -verbose image. You will see those differences.

It really depends upon what you are trying to do. If you want the image to be grayscale to match the way the older versions of IM generated a grayscale image, then my way (the first one) will do that. The second will look gray but have a different gamma and so will display differently and be processed differently according to the gamma value.
caliguian
Posts: 33
Joined: 2012-08-10T12:15:13-07:00
Authentication code: 67789

Re: Color issue when using composite

Post by caliguian »

Great! Thanks for the additional information. It is interesting to me that they decided to make such a large change to the way they handle the images. I have a feeling that quite a few people are going to be having these same issues in the coming years as they update their IM installation.
Post Reply