Composing a sRGB image with a RGB one

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
marcospassos
Posts: 13
Joined: 2014-09-26T08:23:47-07:00
Authentication code: 6789

Composing a sRGB image with a RGB one

Post by marcospassos »

Hello,

I've a layered PSD in sRGB and a RGB image. I'm using Imagick to place this image over a given PSD's layer, simulating the Photoshop's compositing effects. The problem is that the resulting image is darker than the one I see on Photoshop. After some research, I've discovered that setting the colorspace to RGB at the end of the command produces the expected result. The problem is that the image that is in RGB becomes opaque.

sRGB x RGB Result
Image

Expected result:
Image

PSD:
http://www.filedropper.com/teste3602

Image:
Image

Does anyone know how can I solve it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composing a sRGB image with a RGB one

Post by snibgo »

Please tell us what commands you used.

Please say what version of IM you used, on what platform.
snibgo's IM pages: im.snibgo.com
marcospassos
Posts: 13
Joined: 2014-09-26T08:23:47-07:00
Authentication code: 6789

Re: Composing a sRGB image with a RGB one

Post by marcospassos »

Code: Select all

composite -gravity center image.png Global\ Illumination.png output_1.png
composite -compose Multiply Ambient\ Occlusion.png output_1.png output_2.png 
composite -compose LinearDodge Reflection.png output_2.png output_3.png 
I'm running ImageMagick 6.8.9-5 Q16 x86_64 2014-07-25 on OSX 10.9.5.

Used files:
http://ge.tt/4rmQ8r52/v/0?c?c
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composing a sRGB image with a RGB one

Post by fmw42 »

This works for me on IM 6.9.0.0 Q16 Mac OSX. You just need to add an sRGB profile to the png image. It matches your "expected" results, but does not have any of the lighting, reflections, etc. I am not sure which result you want.

unix syntax:

Code: Select all

convert \( teste_3602.psd[0] -alpha off \) \
\( eATzcc3.png -profile /Users/fred/images/profiles/sRGB.icc \) \
-gravity center -geometry -5+0 compose over -composite result.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composing a sRGB image with a RGB one

Post by snibgo »

Your "expected result" doesn't show the reflection, even though this is marked as "correct color" on your first image.

I would use a single "convert" instead of multiple "composites".

IM will happily composite images that are in different colorspaces. It is better to convert them as required to the same colorspace before the composite. I make them RGB, then convert to sRGB at the end.

"-gravity center" isn't quite correct, so I shift the image slightly.

The result seems to be what you want, but with the reflection. Windows BAT syntax; adjust for your system.

Code: Select all

convert ^
  ( "mug\Global Illumination.png" -strip -set colorspace RGB ) ^
  mug\image.png -colorspace RGB ^
  -gravity Center -geometry -5+5 ^
  -compose SrcOver -composite ^
  ( "mug\Ambient Occlusion.png " -strip -set colorspace RGB ) ^
  -compose Multiply -composite ^
  ( mug\Reflection.png -strip -set colorspace RGB ) ^
  -compose LinearDodge -composite ^
  -colorspace sRGB ^
  c.png
  
snibgo's IM pages: im.snibgo.com
Post Reply