I am currently working on the below linked image, and I am having issues getting it to trim correctly. Nothing seems to work better than the below two trim steps. It is leaving a block at the bottom of the image.
Image: http://masejoer.com/Images/blackened.jpg
Output: http://masejoer.com/Images/blackened_trimmed.jpg
Where I'm at so far for all the image processing:
Code: Select all
convert -fuzz 35% -trim -trim in.jpg out.jpg (crop to border)
convert -gamma 0.25 -auto-level -negate -lat 30x30+10% -negate in.jpg out.jpg (helps with cleanup of background noise on darker checks)
convert -morphology close Diamond:2 in.jpg out.jpg (remove noise)
convert -blur 1x1 in.jpg out.jpg (slight blur improves threshold)
convert -threshold 5% in.jpg out.jpg (binarize)
One last thing that I've been unable to figure out - removing everything that is not close to a grayscale pixel. If it has color hues (dark color check backgrounds or non-black pen strokes), turn them white. Closest I've gotten is finding color codes for various colors and using small fuzz values to burn them white. Is there an accurate way to turn non-grayscale pixels white?
Thank you for any help. I've gone about as far as I can after tweaking and testing for over a dozen hours.
Edit: Windows version - ImageMagick-7.0.1-6-portable-Q16-x64. Currently doing all my testing through a batch file.
I have ImageMagick currently setup to have commands, then inputfile and outputfile just for easier readability and tweaking. It's easier to see what I have going on per line. I know some commands don't work unless the input file is first - all of the ones I'm current using work fine as "COMMAND ARGS IN OUT". My batch file actually looks more like this:
Code: Select all
call :Profiler %magick%\convert -fuzz 35%%%% -trim -trim check_step^^!stepold^^!.jpg check_step^^!stepnew^^!.jpg
call :Profiler %magick%\convert -gamma 0.25 -auto-level -negate -lat 30x30+10% -negate check_step^^!stepold^^!.jpg check_step^^!stepnew^^!.jpg
call :Profiler %magick%\convert -morphology close Diamond:2 check_step^^!stepold^^!.jpg check_step^^!stepnew^^!.jpg
call :Profiler %magick%\convert -blur 1x1 check_step^^!stepold^^!.jpg check_step^^!stepnew^^!.jpg
call :Profiler %magick%\convert -threshold 5%%%% check_step^^!stepold^^!.jpg check_step^^!stepnew^^!.jpg