lucians
lucians

Reputation: 2269

Run ImageMagick TextCleaner on batch files

It is possible to use the TextCleaner script provided by Fred Weinhaus on batch files ?

I didn't find anything about this. I searched and for other scripts there are various methods but not for TextCleaner. There is a "universal" command to run ?

I use Cygwin on Windows to execute the script.

I am also new to ImageMagick so I don't know too much..

This is the command I use:

textcleaner -g -e normalize -f 50 -o 10 -s 10 image_0in.png image_out.png

Upvotes: 0

Views: 864

Answers (2)

ESP32
ESP32

Reputation: 8728

This is not the full Weinhaus script of course, but it does the basic image enhancement you are looking for:

textcleaner.bat

cd /d %~dp0

set filtersize=40
set offset=5

FOR %%i in (%1) do (
    del/q "%%~dpni.new3.png"
    echo Cleaning %1 ...
    "Z:\_grafik\imagick\bin\convert" -respect-parenthesis ^( "%1" -colorspace gray -set colorspace RGB -contrast-stretch 0 ^) ^( -clone 0 -negate -contrast-stretch 0 -lat %filtersize%x%filtersize%+%offset%%% ^) -compose Copy_Opacity -composite -fill white -opaque none +matte -deskew 50%% -alpha off "%%~dpni.new.png"
)

Usage:

textcleaner.bat myimage.png
---> will create myimage.new.png

Upvotes: 0

fmw42
fmw42

Reputation: 53154

My textcleaner script will only process one image at a time. You will have to write a script loop over each image you want to process and then call textcleaner for each image in the loop.

You can create a list manually of all images you want to process. Or if all your images are in one directory (and they have no spaces in the names), then you can do

cd to directory holding the images
list=`ls`
for img in $list; do
name=`convert $img -format "%t" info:`
textcleaner -g -e normalize -f 50 -o 10 -s 10 $img ${name}_out.png
done


or better (even if files have spaces in the names)

cd to directory holding the images
for img in *.png; do
name=`convert "$img" -format "%t" info:`
textcleaner -g -e normalize -f 50 -o 10 -s 10 "$img" "${name}_out.png"
done

Upvotes: 2

Related Questions