Skip to content

Instantly share code, notes, and snippets.

@lelandbatey
Last active November 11, 2024 22:46
Show Gist options
  • Save lelandbatey/8677901 to your computer and use it in GitHub Desktop.
Save lelandbatey/8677901 to your computer and use it in GitHub Desktop.
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

Here are some of the input images:

And here are the results:

Usage

Assuming it's saved as a file named whiteboardClean.sh, the command is ./whiteboardClean.sh {name of input file} {name of file to output to}.

Here's an example:

./whiteboardClean.sh example1.jpg output1.png

How I Came Up With This

I was doing a lot work with whiteboards and I'd been taking pictures of them to document what had been written. I wanted a more clean version of the pictures though, something that captured the essence of what a whiteboard image showed.

Eventually I found this excellent guide to cleaning up whiteboard photos using GIMP. However, I found I wanted more automation. So, I spent a few hours yesterday figuring out how to do the same thing using ImageMagick from the command line and made this script.

@kinduff
Copy link

kinduff commented Apr 4, 2014

@lelandbatey Good job, bro!

If you guys want to convert that output png to a svg vector format, you can use AutoTrace to archive this.

I'm currently using the following command with these options, if you find a better solution, please post it here :)

./autotrace \
  --dpi 1024 \
  --line-threshold 0.1 \
  --color-count 16 \
  --corner-always-threshold 60 \
  --line-reversion-threshold 0.1 \
  --width-weight-factor 0.1 \
  --despeckle-level 10 \
  --despeckle-tightness 5 \
  --preserve-width \
  --remove-adjacent-corners \
  --output-format svg \
  --output-file out.svg \
  in.png

in.png
out.svg

@LucasArruda
Copy link

Amazing!

@LucasArruda
Copy link

Amazing!

@anthonyray
Copy link

That's great !

@sourcegate
Copy link

Just wanted to say thanks for sharing was super useful for me. I'm always doing these in Photoshop and this is a huge time saver for me.

@gsdean
Copy link

gsdean commented Apr 9, 2014

@ShivendraAgrawal
Copy link

Could somebody help me with identification of the image processing algorithms used? And the order in which they were used?

@captainpete
Copy link

Incredible!!

@delegans
Copy link

delegans commented May 7, 2014

Web service: upload and clean white board on-line

http://api.o2b.ru/whiteboardcleaner

@m-space
Copy link

m-space commented May 16, 2014

For anyone stuck on a Windows platform, you can save this slightly modified version to whiteboardClean.bat:

convert %1 -morphology Convolve DoG:15,100,0 -negate -normalize -channel RBG -level 60%%,91%%,0.1 %2

You can further improve the batch file to loop over multiple image files. Usage: batchClean.bat *.jpg

FOR %%A IN (%*) DO (
    convert %%A -morphology Convolve DoG:15,100,0 -negate -normalize -channel RBG -level 60%%,91%%,0.1 cln_%%A
)

@greywolve
Copy link

Thank you! Works great :)

@projectdevan
Copy link

Checkout this new service http://www.brightboard.co.in/ . It is pretty basic and non secure now and is in devel mode. Started it as a new service. Help to make it better by giving your suggestions

@mburr
Copy link

mburr commented Aug 10, 2015

Thank you so much for posting the one liner - my own little bit of monkeying around didn't work well. This does a great job!

@peterjamesbaldwin-myob
Copy link

Great work.

@amn41
Copy link

amn41 commented Sep 14, 2016

@lelandbatey any tips on fixing the way the text looks here? http://imgur.com/a/dWddi I thought it was maybe bc I fed it a jpg but I converted to png & still get blurry / hard-to-read text

@mickdee
Copy link

mickdee commented Nov 29, 2016

When trying to run the same command in the readme on Mac Sierra I get the following error (I have a test image in the same directory from which I'm running the command):

convert: unable to load module `/usr/local/Cellar/imagemagick/6.8.9-1/lib/ImageMagick//modules-Q16/coders/jpeg.la': file not found @ error/module.c/OpenModule/1282.
convert: no decode delegate for this image format `JPEG' @ error/constitute.c/ReadImage/501.
convert: no images defined `imageclean.png' @ error/convert.c/ConvertImageCommand/3187.

@bruceathome
Copy link

Hi. Blatant ask for assistance - is there any way to get a similar script to run in python (actually pythonista on an ipad)? My students (high school) send me photographs of their responses to questions. I then save these on my iPad and use a script? in the 'workflow' app which rotates the images (if necessary) and converts them to pdf, which I then open in another app (notability) so that I can annotate and then email them back to the students. I would like to use the above script as part of my workflow script to automate everything. My thoughts are to use pythonista (which 'workflow' can talk to) to run something similar to the script above to clean up the students photographs. Sorry for the long-winded ask for help (non-programmer here).

@henrebotha
Copy link

@bruceathome did you manage? I can try and help you. Drop me an email (address here https://github.com/henrebotha).

@Bersaelor
Copy link

Next step:
Replicate same line with CIFilters and put it in an app, so you don‘t have to export them to PC first.

@yekm
Copy link

yekm commented May 24, 2018

@luisDVA
Copy link

luisDVA commented Jun 2, 2018

has anyone here used this workflow in the 'magick' package in R?
I can't replicate the last bit because I can't figure out how the -level operator was implemented

Copy link

ghost commented Sep 10, 2018

Hello everyone,

Anyone know how to apply this Whiteboard script for swift or objective C Or any other way to use in iOS?

@john-dgi-vof-com
Copy link

oooh wauwie !!! I have been looking for this method for hundreds of years ;-) thanks man!!

@Deliaz
Copy link

Deliaz commented Feb 27, 2019

Hello everyone,

Anyone know how to apply this Whiteboard script for swift or objective C Or any other way to use in iOS?

Let me know please, If you will find anything. Thanks.

@bwjohnson-ss
Copy link

👏

@Napolitain
Copy link

Napolitain commented Sep 25, 2019

I'm getting an error :

convert: ../../magick/quantum.c:216: DestroyQuantumInfo: Assertion `quantum_info != (QuantumInfo *) NULL' failed.
scanner.sh: line 2:     9 Aborted                 (core dumped) convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

I use Ubuntu WSL for Windows 10 and installed the library obviously (ImageMagick). I tried it on a 32000*27000 png image (max format for PNG fyi).

I would also prefer to use it on my initial PDF but it seems it does not work?

@Napolitain
Copy link

Okay, the PNG error is not corrected but I finally found out how to use it on my PDF using this link : https://alexvanderbist.com/posts/2018/fixing-imagick-error-unauthorized

I had a "Unauthorized" error so I nanoed a config file.

@Fresher14
Copy link

I ran this script in a corporate unix environment and it works great. Just rather slow.
Great job, thank you.

@santhalakshminarayana
Copy link

santhalakshminarayana commented Oct 18, 2021

I had converted the above ImageMagick commands to OpenCV Python with some adjustments for white-board image enhancement.
If any one interested for Python implementation, find the script in white_board_enhance github repo.

@the-invisible-man
Copy link

So damn cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment