Page 3 of 3

Re: how to use ImageMagick to remove punch holes?

Posted: 2016-11-11T13:37:57-07:00
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

Re: how to use ImageMagick to remove punch holes?

Posted: 2016-11-12T11:13:28-07:00
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