Page 1 of 2
Watermark removal, please help [solved]
Posted: 2017-04-11T06:11:21-07:00
by BradLee
Hi,
I have a number of B+W photos that I need to remove a watermark from.
Unfortunately I lost the backup of the original images and only have the watermarked copies.
I am able to do this by layering the watermarked photos with the watermark in paint.net and performing a "difference."
However I have nearly 1200 images to do this for, and it would take me an eternity to do it by hand.
So I was hoping that I can achieve something similar in ImageMagick, running it as a batch?
E.g
Watermarked Image:
http://i1219.photobucket.com/albums/dd4 ... fp7j2k.png
Watermark:
http://i1219.photobucket.com/albums/dd4 ... dm6zdg.png
Difference Image:
http://i1219.photobucket.com/albums/dd4 ... gdp604.png
Inverted (final) Image:
http://i1219.photobucket.com/albums/dd4 ... opqyng.png
Can someone please help me with this? I'm really out of my depth.
I currently have ImageMagick-7.0.5-4.x86_64.rpm, and am using Windows 7 Pro.
Thanks,
BradLee
Re: Watermark removal, please help.
Posted: 2017-04-11T08:29:12-07:00
by snibgo
If the watermark contains fully opaque pixels, these will have overwritten the input, so we can't calculate them. A hole-filling ("inpainting") technique might guess them.
If your watermark contains no fully-opaque pixels, and was effectively applied with "-compose Over -composite", and you know exactly where is was applied, the inverse process can easily be applied get the source image back.
Can you post the watermark image, and a watermarked image (or at least the portion that contains the watermark). You can upload to somewhere like dropbox.com and paste the URLs here.
EDIT: While I was replying, you uploaded them. I'll take a look.
Re: Watermark removal, please help.
Posted: 2017-04-11T08:41:08-07:00
by snibgo
Your watermark is fully opaque, so it clearly wasn't applied with "-compose Over -composite". Do you know how it was applied?
Re: Watermark removal, please help.
Posted: 2017-04-11T09:17:00-07:00
by GeeMack
BradLee wrote: ↑2017-04-11T06:11:21-07:00I am able to do this by layering the watermarked photos with the watermark in paint.net and performing a "difference."
I'm using IM 7.0.5-4 on Windows 10 64. I downloaded your example image with the watermark, and your example watermark image, then I ran this command...
Code: Select all
magick image-with-watermark.png watermark.png -compose difference -composite -negate output.png
The result appears to be the original image with the watermark removed.
Re: Watermark removal, please help.
Posted: 2017-04-11T09:30:21-07:00
by BradLee
GeeMack wrote: ↑2017-04-11T09:17:00-07:00
Code: Select all
magick image-with-watermark.png watermark.png -compose difference -composite -negate output.png
The result appears to be the original image with the watermark removed.
Yes, that works. Thanks.
Now is there any way I can perform this on a whole folder of images?
Cheers.
EDIT: I think i should be using:
Code: Select all
magick *.png watermark.png -compose difference -composite -negate
But not sure how to output to multiple files?
EDIT2: It would be even better if I could save the output over the top of each of the files, so that they kept the same file names.
Re: Watermark removal, please help.
Posted: 2017-04-11T09:46:53-07:00
by fmw42
Try mogrify (IM 6) and magick mogrify (IM 7) with -draw to do the composite. See
http://www.imagemagick.org/Usage/basics ... fy_compose. Use difference rather than dst_in.
Mogrify will process all images in a folder. I suggest you create a new folder to hold your output before running mogrify, but it will allow you to keep the same names.
Code: Select all
magick mogrify -path path2/newfolder -format png -draw "image difference 0,0 0,0 'path2/watermark.png'" -negate *.png
Note that the watermark image should not be in the same folder as your other images, since all are png.
EDIT: I forgot the -negate. So I have modified the above to add it.
Re: Watermark removal, please help.
Posted: 2017-04-11T09:57:51-07:00
by GeeMack
BradLee wrote: ↑2017-04-11T09:30:21-07:00Now is there any was I can perform this on a whole folder of images?
If the watermark is the same size and location, in other words if you can use the same single image as your watermark template, and all your original images are the same size and orientation, you should be able to run a whole folder with a command something like this...
Code: Select all
magick *.png -set filename:f "%[t]" null: watermark.png ^
-compose difference -layers composite -negate "cleaned\%[filename:f].png"
The results will be the same file names saved into a folder named "cleaned". Make sure you create the directory "cleaned" before you run it. You could adjust that command so it overwrites your originals by leaving out the "cleaned" directory name, but if something doesn't go as planned, you'll be sorry.
Also, if you'll be using this in a BAT script, make sure to change any single percent signs "%" to doubles "%%".
Edited to add: As
fmw42 mentioned above, since your watermark image will also match "*.png", you may want to call it in from a location other than the folder with your working images.
Re: Watermark removal, please help.
Posted: 2017-04-11T10:13:07-07:00
by fmw42
Always good to see multiple ways to do the same thing. IM 7 is more powerful than IM 6 and thus GeeMack's solution shows how a simple magick command can replace mogrify.
Re: Watermark removal, please help.
Posted: 2017-04-11T10:23:01-07:00
by BradLee
All the images are the same size and the watermark is in the same location. (luckily)
I think I'll attempt this tomorrow when it's not so late and my head is a little less lumpy.
Thanks
GeeMack,
fmw42 and
snibgo for your help.
Re: Watermark removal, please help.
Posted: 2017-04-11T10:31:03-07:00
by snibgo
You have 1200 images, each 791x1024 pixels. The solution starting with "magick *.png" needs 7.7 GB of memory just to read the images. If you run out of memory, this will be slow, or might fail.
The solution that starts with "magick mogrify" won't have that problem.
Re: Watermark removal, please help.
Posted: 2017-04-11T17:26:41-07:00
by BradLee
@fmw42
Trying your code above gives me the following errors:
Code: Select all
magick mogrify -path C:\Users\Brad\Downloads\padded -format png -draw "image difference 0,0 0,0 'C:\Users\Brad\Downloads\watermark\watermark.png'" -negate *.png
mogrify: unable to open image '*.png': Invalid argument @ error/blob.c/OpenBlob/
3094.
mogrify: unable to open file `*.png' @ error/png.c/ReadPNGImage/4354.
Re: Watermark removal, please help.
Posted: 2017-04-11T17:31:56-07:00
by BradLee
@GeeMack
Using your code above gives me the following errors:
Code: Select all
magick *.png -set filename:f "%[t]" null: watermark\watermark.png -compose difference -layers composite -negate "cleaned\%[filename:f].png"
magick: unable to open image '*.png': Invalid argument @ error/blob.c/OpenBlob/3
094.
magick: unable to open file `*.png' @ error/png.c/ReadPNGImage/4354.
magick: no image to apply a property "%w" @ warning/property.c/GetMagickProperty
Letter/2561.
magick: unknown image property "%w" @ warning/property.c/InterpretImagePropertie
s/3499.
magick: no image to apply a property "%h" @ warning/property.c/GetMagickProperty
Letter/2449.
magick: unknown image property "%h" @ warning/property.c/InterpretImagePropertie
s/3499.
magick: no image to apply a property "%m" @ warning/property.c/GetMagickProperty
Letter/2480.
magick: unknown image property "%m" @ warning/property.c/InterpretImagePropertie
s/3499.
Although I don't think I have the usage right at all?
Re: Watermark removal, please help.
Posted: 2017-04-11T17:34:31-07:00
by BradLee
snibgo wrote: ↑2017-04-11T10:31:03-07:00
You have 1200 images, each 791x1024 pixels. The solution starting with "magick *.png" needs 7.7 GB of memory just to read the images. If you run out of memory, this will be slow, or might fail.
The solution that starts with "magick mogrify" won't have that problem.
I have 16GB RAM and the images are in folders of roughly 200 each, so running out of memory shouldn't be a problem if I can get either solution to work properly.
Re: Watermark removal, please help.
Posted: 2017-04-11T18:37:02-07:00
by GeeMack
BradLee wrote: ↑2017-04-11T17:31:56-07:00Using your code above gives me the following errors:
I can generate exactly that error by running the command in a directory with no .png files.
Re: Watermark removal, please help.
Posted: 2017-04-11T19:11:07-07:00
by BradLee
@GeeMack,
I thought I ran it from the right directory?
Let me check again.
EDIT: My mistake. It works just fine.
I'm a bit of a dunce when it comes to command line stuff.
Thanks again for your help!