jaudo
jaudo

Reputation: 2122

Extract watermark from image

I've got 2 versions of 1 image

1 image without watermark the same image, with a alpha-blended watermark

Is it possible to get a transparent png file representing this watermark? Can ImageMagick do this?

Upvotes: 1

Views: 2765

Answers (2)

fmw42
fmw42

Reputation: 53091

SilverMonkey has the basic solution using Imagemagick. But the request was for a transparent PNG. So I will add a little bit more to his code to make it transparent by adding -alpha copy.

convert kitty2.jpg kitty1.jpg -compose minus -composite -auto-level -alpha copy watermark1.png

enter image description here


Here is another approach that makes a binary mask for the watermark by thresholding. But it leaves a lot of noise. So I use some morphology open to remove the noise and then some morpholgy close to try to fill in where the text is broken up. Then I add -alpha copy to make the image transparent. But the text is white and the original watermark was light gray. So I turn alpha off, multiply by 0.75 to reduce the brightness of the white letters to gray without affecting the alpha channel. Then turn the alpha channel back on.

convert kitty2.jpg kitty1.jpg -compose minus -composite -threshold 0.6% -morphology open diamond:1 -morphology close octagon:1 -alpha copy -alpha off -evaluate multiply 0.75 -alpha on watermark2.png


enter image description here

For more on morphology, see https://imagemagick.org/Usage/morphology/

Upvotes: 2

SilverMonkey
SilverMonkey

Reputation: 1003

You can achieve your goal by calculating the difference between both images (subtract the pixels of both images and calculate the absolute value). This will result in: Subtracted image ImageMagick seems to be capable of image subtraction, look here: The code:

convert image2 image1 -compose minus -composite result

Upvotes: 1

Related Questions