Subtracting 100% match only?

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
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Subtracting 100% match only?

Post by Rye »

So,

Let's assume I want to "subtract" this image:

Image

from this:

Image

Thereby removing the Logo in the back completly, without harming the image in the foreground.

Is this possible by using imagemagick (preferably without masking etc.)

Regards:

Rye
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Subtracting 100% match only?

Post by snibgo »

With a difference composite, we can find which pixels are identical in the two images. Then we can use that as a mask to do whatever we want, such as turning those pixels transparent in the second image.
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: Subtracting 100% match only?

Post by fmw42 »

What is your IM version and platform? Please always provide that when asking questions, since syntax may differ.
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Subtracting 100% match only?

Post by Rye »

Version in sig.

For now this is what I came up with... :?

Code: Select all

@echo off
mkdir BG | move BG.png BG
for %%x in (*png) do convert %%x BG/BG.png -compose difference -composite -threshold 0 -separate -evaluate-sequence Add mask.png
convert mask.png  -alpha remove mask.png
convert mask.png -transparent "#FFFFFF" mask.png
move mask.png BG
for %%x in (*.png) do convert -page +0+0  %%x   -page +0+0 BG/mask.png -flatten %%x
cd BG
move BG.png ..
cd BG|del *.png
pause
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply