image multiplication?

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
rubinglen
Posts: 3
Joined: 2014-06-19T08:19:28-07:00
Authentication code: 6789

image multiplication?

Post by rubinglen »

Hi all!

I have two same-sized black on white images (image1.png image2.png). I would like to merge these images in such a way that the locations where both images are black are turned to white in the composite image.

I tried making some commands using compose and multiply, but I didn't have much luck. I think there was something very wrong with my commands...I am very new to image processing and could use some advice on this. Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image multiplication?

Post by snibgo »

You might compose them. See http://www.imagemagick.org/Usage/compose/

What result do you want when one or other isn't black? I mean, just setting the result to white, no matter what, would satisfy your requirement!
snibgo's IM pages: im.snibgo.com
rubinglen
Posts: 3
Joined: 2014-06-19T08:19:28-07:00
Authentication code: 6789

Re: image multiplication?

Post by rubinglen »

That's a good question, obviously I didn't explain well b/c I did not think this out thoroughly.


More precisely:

I would like to remove (turn white) from image1.png any places where image 1.png and image2.png have overlapping black pixels. All the rest of image1.png I want to leave the same.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image multiplication?

Post by snibgo »

Okay. You want the output to be input #1, except that where both inputs are black, you want white. This will do it, but there may be a better way. Windows BAT syntax:

Code: Select all

convert ^
  g1.png ^
  ( +clone ^
    g2.png ^
    -negate ^
    -compose Multiply -composite ^
    -alpha set +transparent White ^
  ) ^
  -compose Over -composite ^
  out.png
snibgo's IM pages: im.snibgo.com
rubinglen
Posts: 3
Joined: 2014-06-19T08:19:28-07:00
Authentication code: 6789

Re: image multiplication?

Post by rubinglen »

that works, thanks!
Post Reply