how to use ImageMagick to remove punch holes?

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?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to use ImageMagick to remove punch holes?

Post by snibgo »

There are many ways of doing "for" loops, and it's outside the scope of this forum, but this should get you started.

You currently have a script that takes an input file called 1.jpg, and an output file called h_bf.png. What is this script called? I'll pretend it is called "myscript.bat".

Change all occurrences of 1.jpg to %1.

Change all occurrences of h_bf.png to %2.

Now, whenever you call this script, you need to provide these two parameters. Test it to make sure it works:

Code: Select all

call myscript 1.jpg new_out.png
Then you can write another script that contains something like:

Code: Select all

for %%F in (*.jpg) do call myscript %%F %%~nF.png
snibgo's IM pages: im.snibgo.com
Adam32
Posts: 20
Joined: 2016-11-08T11:18:35-07:00
Authentication code: 1151

Re: how to use ImageMagick to remove punch holes?

Post by Adam32 »

Thank you so much for all your help. This following workflow seems to work quite well, . The left is processed first and then the right, with the final results in a folder called output I also have the script delete all the source image files when processing is complete.

Here are the scripts:

start.bat

Code: Select all

call left 1.jpg new_out.png

for %%F in (*.jpg) do call left %%F %%~nF.png

call right 1.png new_out.png

for %%F in (*.png) do call right %%F %%~nF.png

del *.jpg *.png
Left.bat

Code: Select all

convert  %1  -threshold 50%%  -define connected-components:verbose=true  -define connected-components:area-threshold=190  -define connected-components:mean-color=true  -connected-components 8  t2.png

convert  %1  ( t2.png -crop 10%%x100%%+0+0 ^ -morphology Erode disk:3  )  -alpha off  -set option:compose:outside-overlay false  -compose CopyOpacity -composite  h.png

blurFill.bat h.png . %2
Right.bat

Code: Select all

convert  %1  -threshold 50%%  -define connected-components:verbose=true  -define connected-components:area-threshold=150  -define connected-components:mean-color=true  -connected-components 8  t2.png

convert  %1  ( t2.png -gravity East -crop 10%%x100%%+0+0 ^ -morphology Erode disk:3  )  -alpha off  -set option:compose:outside-overlay false  -compose CopyOpacity -composite  h.png

blurFill.bat h.png . output\%2
Post Reply