Trimming and cleaning up large number of photographed checks

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?".
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Trimming and cleaning up large number of photographed checks

Post by Masejoer »

snibgo wrote:
snibgo wrote:convert image_original -crop -blur 0x8 -threshold 45% -trim image_step1
Yeah, sorry, remove the "-crop".
Wouldn't this also blur the output? Doing it the other way, I get the crop coordinates with a blur, but then crop on the original sharper image.
snibgo wrote:

Code: Select all

convert c:pictures\palette.png ( +clone -colorspace HCL -channel G -separate +channel -auto-level -threshold 40% +write x.png ) -compose Lighten -composite grey_pal.png
This is my result, with v6.9.2-5:
Image
Lower the threshold, eg to 10%, to turn more colours to white.

If you are using BAT files, you have doubled the %, haven't you?
I'll play with it some more. Yes, it's batch file, and yes I actually have extra % symbols to make it work. In this thread I'm stripping these down to the basics so it's easier for the public to read.
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Trimming and cleaning up large number of photographed checks

Post by Masejoer »

snibgo wrote:

Code: Select all

convert c:pictures\palette.png ( +clone -colorspace HCL -channel G -separate +channel -auto-level -threshold 40% +write x.png ) -compose Lighten -composite grey_pal.png
This is my result, with v6.9.2-5:
Image
Lower the threshold, eg to 10%, to turn more colours to white.
Beautiful. Works very nicely! I was missing the "-composite" argument earlier...

Don't think I can improve the OCR pre-processing much more than this. Hope to improve performance next by either order of operations, or tweaks to some values. 16MP images take some time to process. After completion, I assume I'll be able to feed a lot of this into one or two convert.exe calls, depending on the limitations of IM, or command line character lengths.

Current batch testing script expects list of filename.extension values in imagelist.txt. You can see why I had to modify code-blocks earlier in the thread as this thing is difficult to read:

Code: Select all

@ECHO OFF
SetLocal EnableDelayedExpansion
set Magick=D:\Downloads\ImageMagick-7.0.1-6-portable-Q16-x64
set ext=bmp

for /f %%A in (imagelist.txt) do (
	set step=0
  	set imagename=%%A
  	del .\!imagename!\image_step*

	call :Profiler %magick%\convert .\images\!imagename!  -alpha set -auto-level -auto-gamma -compress none .\!imagename!\image_step^^!stepnew^^!.!ext!
	
	FOR /F "tokens=* USEBACKQ" %%F IN (`%magick%\convert .\!imagename!\image_step1.!ext! -blur 0x8 -threshold 45%% -format %%@ info:`) DO (SET var=%%F)
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -crop !var! .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! ^( +clone -colorspace HCL -channel G -separate +channel -auto-level -threshold 20%%%% +write x.png ^) -compose Lighten -composite .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -colorspace gray  -negate -lat 80x80+10%%%% -negate .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -resize 3000 .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -gravity South -chop 0x8%%%% .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -chop 0x89%%%% .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -gravity East -chop 20%%%%x0 .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -gravity West -chop 4%%%%x0 .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -morphology close Diamond:1 .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -gamma 0.25 -auto-level .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -blur 1x1 .\!imagename!\image_step^^!stepnew^^!.!ext!
	call :Profiler %magick%\convert .\!imagename!\image_step^^!stepold^^!.!ext! -threshold 60%%%% .\!imagename!\image_step^^!stepnew^^!.!ext!
	
	start .\!imagename!\image_step1.!ext!
	start .\!imagename!\image_step!step!.!ext!
)

exit

:Profiler
set start=%time%

set stepold=%step%
set /a stepnew=%step%+1
cmd /c %*
set step=%stepnew%

set end=%time%
set options="tokens=1-4 delims=:."
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100

set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %hours% lss 0 set /a hours = 24%hours%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if 1%ms% lss 100 set ms=0%ms%

set /a totalsecs = %hours%*3600 + %mins%*60 + %secs% 
echo.
echo Command "%*"
echo Took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)

goto :eof
Post Reply