Great work, thanks heaps for this! This'll help me clean up files quickly and easily, as we do the same thing a lot of the time too :)
NB: This works fine on the Windows version of ImageMagick, however if (like me) you want to wrap it in a batch file you must escape the -level command by changing the "60%,91%,0.1" to "60%%,91%%,0.1" or else the batch file will misinterpret it, since %1 refers to variable names (the same as bash scripts). If you don't, you'll just get a black PNG file.
I got excited when i saw the results since they looked awesome, such that I thought I could replace my quick&dirty transparent GIFs script[1], but apparently it has issues with low-resolution images.
For those of you who would like to use this on smaller images, play around with "DoG:15,100,0". This string refers to implementing a difference of gaussian filter with inner radius of 15 and outer radius of 100 pixels. This is obviously tied to image size. The first number should always be smaller than the second, and my guess is that it should be on the order of the average width of the text. Just a estimation, I don't have the time to test it right now.
Heh, I remember this from when you posted it on reddit months ago [1]. Glad to see you're the same person and you didn't just take it from them. Very nice script, I've used it before with great success.
Cool! I did something similar just recently for cleaning up scans of my laboratory notes (in a moleskin). I have an Automator action which watches the scan folder, automatically crops/splits the pages and cleans them up, then uploads them into Evernote. Gives me a searchable cloud backup of my lab notes!
This seems similar to what I've had to do with OpenCV in various iOS apps, but I think your results are more impressive than mine.
I had to sacrifice some quality in order to be able to do this with realtime video, but still, I should probably work out exactly what processing that command actually does and see if I can improve quality while still meeting the realtime requirement.
On a slightly related note, camscanner, an app for android (and IOS?) does something similar, but can also correct for the angle at which the photo was taken (I think it has to detect squares/rectangles in the photo). Does anyone know if this is possible using the command line too?
I'm doing an online whiteboard (spacedeck.com) and always wondering how to bridge the analog/physical world of whiteboard scribbles and sticky notes and software. How would you continue to work with these images? Attach them to a task? What is the workflow?
Here's the comment I posted on the Gist, copy-pasted to here:
@molven, @vibragiel: Wow, I feel more than a bit ridiculous after looking into this. Turns out, those original examples I made using GIMP (same basic process, tuned the parameters to make it look nice). I'd originally put this gist together several months ago, and I hadn't done a thorough enough check before submitting to HN.
HOWEVER, I've since created new examples actually using the bash script, and the gist has been updated accordingly.
Take a look at Tesseract, which last time I looked was the best codebase to use in this area. It's part of Google's open source multilingual OCR suite, which is in two parts (layout analysis and actual OCR code being segregated): https://code.google.com/p/tesseract-ocr/
Is there a guide to using tesseract? When I last used it, I had trouble accurately recovering text from an image I just created with Times New Roman. There are probably some settings I'd need to change to get it to work properly.
Not sure. I looked at it years ago, during its early open source stages, and similarly concluded that it was nontrivial to get going. Should be easier now. IIRC in those days it had a very high volume mailing list for user support.
If you have black-on-white then try adding -negate after the source image, it'll turn it to black-on-white.
Another approach I took recently was to combine this with -threshold (90 worked well in my case) and the Dilate morphology - I had a black and white set of plans printed using varying-sized dots.
NB: This works fine on the Windows version of ImageMagick, however if (like me) you want to wrap it in a batch file you must escape the -level command by changing the "60%,91%,0.1" to "60%%,91%%,0.1" or else the batch file will misinterpret it, since %1 refers to variable names (the same as bash scripts). If you don't, you'll just get a black PNG file.