composite -compose screen @some % of overlay image?

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
rutile
Posts: 3
Joined: 2012-03-12T20:46:58-07:00
Authentication code: 8675308

composite -compose screen @some % of overlay image?

Post by rutile »

I've been combining two images with a straight blend, so that the final image is some percent of the overlay and the background. Like so:

composite -blend 25 overlay.jpg background.jpg destination.jpg

Now I'd like to do the same thing, but in screen or multiply mode. I thought it would be a simple matter of replacing -blend with -screen, but apparently it isn't that simple.

All I want to do is replicate a GIMP layering, where two layers are combined in screen mode, and the layer on top is only visible or weighted at 25%.

I know this should be pretty easy, but it escapes me, any help is appreciated.

Thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: composite -compose screen @some % of overlay image?

Post by anthony »

-blend is a specialised composition that weights the two images before adding (plus) them together.
http://www.imagemagick.org/Usage/compose/#blend
-dissolve is very similar but performs an over composition.
http://www.imagemagick.org/Usage/compose/#dissolve

To do this with screen or multiply does not make sense. mathematically a weighted multiple (or for screen negated multiply) is just a same as doing the multiply of the images and a constant!


An alternative to blend is to use the special 'mathematic' compostion
http://www.imagemagick.org/Usage/compose/#mathematics

EG; using convert options...

Code: Select all

   -compose blend -define compose:args=25x75  -composite
and

Code: Select all

   -compose mathematics -define compose:args=0,0.25,0.75,0  -composite
should produce the same results.

WARNING: mathematics uses 'screen' alpha blending when alpha channels are present, just like the other mathematical composition methods. Blend however uses 'blend' alpha blending.
See Mathematical Composition and Alpha Blending
http://www.imagemagick.org/Usage/compose/#math_blending

ASIDE: looks like their is a bug in mathematical blending without the 'sync' channel flag. -- I have noted it, to have a look.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rutile
Posts: 3
Joined: 2012-03-12T20:46:58-07:00
Authentication code: 8675308

Re: composite -compose screen @some % of overlay image?

Post by rutile »

thanks, but maybe we talking at cross purposes? I'm not sure if I understand what you are suggesting. I'm ok with the blend mode for where I need to use that. What I need to do now is combine two images in screen mode. A background image with a starfield, and black silhouetted foreground, and an overlay image with the foreground illuminated showing detail. I want to combine the two images using screen, so that where the background image is purely black, about 25% of the overlay image foreground detail shows through. In Gimp, I make the foreground image 25% opaque, and use screen mode. I need to do this with several hundred images, each time I make a scene, so I'd like to do it in imagemagick. I'm rather dense when it comes to figuring out the command line options through, for example, in your examples, I'm not sure where the input image designations go, and I don't think those commands give me a screen mode?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: composite -compose screen @some % of overlay image?

Post by anthony »

Sounds like a masked composition to me.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
stupid
Posts: 51
Joined: 2010-02-12T07:30:34-07:00
Authentication code: 8675308

Re: composite -compose screen @some % of overlay image?

Post by stupid »

Try this.

convert BOTTOM_IMAGE ( TOP_IMAGE -alpha Set -channel A -evaluate Multiply 0.25 +channel ) -compose Screen -composite OUT.JPG

s.
rutile
Posts: 3
Joined: 2012-03-12T20:46:58-07:00
Authentication code: 8675308

Re: composite -compose screen @some % of overlay image?

Post by rutile »

stupid wrote:Try this.

convert BOTTOM_IMAGE ( TOP_IMAGE -alpha Set -channel A -evaluate Multiply 0.25 +channel ) -compose Screen -composite OUT.JPG

s.
Stupid isn't so stupid ;)

My terminal doesn't like the parenthesis, but without them it seems to work. It doesn't exactly replicate the GIMP version, but I think that I can work with it.
thanks a lot. I couldn't make these images without imagemagick.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: composite -compose screen @some % of overlay image?

Post by anthony »

Without the parenthesis, you are applying the alpha channel dissolve to BOTH images, not just one image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
stupid
Posts: 51
Joined: 2010-02-12T07:30:34-07:00
Authentication code: 8675308

Re: composite -compose screen @some % of overlay image?

Post by stupid »

It's worth noting that the parentheses require spaces on both sides of each character. Eg SPACE(SPACE... SPACE)SPACE. You could also try escaping the parentheses: \(... \). On Windows that would be ^(... ^).

s.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: composite -compose screen @some % of overlay image?

Post by anthony »

windows does not need escaping for parenthesis
http://www.imagemagick.org/Usage/windows/#dos
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply