Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!


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:

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


Here are some of the input images:

And here are the results:


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

Here's an example:

./ 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.

Definitely make it into a bash/zsh alias :)

This would be great to hook up to a webcam that constantly takes pictures of a whiteboard (or with the press of a button) for documenting brainstorming sessions

kreely commented Apr 3, 2014

This is great. Well done.

johndeng commented Apr 3, 2014

So great. I love it.

magus commented Apr 3, 2014

Not experiencing the same results with the same example images.

⇨ convert -version Version: ImageMagick 6.8.6-3 2014-03-23 Q16 Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC Features: DPC Modules Delegates: bzlib freetype jng jpeg png xml zlib


Unreal, well done.


lelandbatey commented Apr 3, 2014

@magnus The source images where actually higher resolution. Here's the first input image, and here's the second input image.

I don't know why github decided to display tiny, compressed versions in the gist summary.

molven commented Apr 3, 2014

I tested the higher resolution example with 3 colors and can't find the result to be similar. The text, especially the red, does not look good. Did you use the same parameters when you made the examples above?

My result:
ImageMagick 6.7.7-10 2014-03-06 Q16


ghost commented Apr 3, 2014

Good work, thanks for sharing!

Wow! This is very good. I applied this to my first startup comic. Results are below.



mikaa123 commented Apr 3, 2014

Amazing work man!
Gonna try it soon and tell you how it turned out

I'm getting the same output as @molven with exactly the same ImageMagick version.


lelandbatey commented Apr 3, 2014

@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.

You can get these images here:



xpepper commented Apr 3, 2014

Hi @lelandbatey, thanks for the idea.
I edited a bit your shell script to surround the two arguments ($1, $2) with double quotes, so that any space in the image path does not cause problem.

apetrov commented Apr 3, 2014

actually it would be easier to create a (z)sh function:
whiteboard () {
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

This is simple and effective. Many such photos ive taken lie unattended. Now i can clean them up and save.

The output files are suitable for png optimisation, using something like pngquant

On Output1 and Output2 the pngquant defaults got the file sizes to 42% and 38% of the original sizes respectively.

marcaube commented Apr 3, 2014

I would've loved this when I was in college! So much note-taking and so little listening ...

rylwin commented Apr 4, 2014


Please, add quotes around $1 and $2 to support long file names in your great script! =)

Works a treat :D

It's also nice for selfies :)

great stuff, I just added to my bashrc

white-board-cleaner () { convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2; }

statico commented Apr 4, 2014

If you want to make an AppleScript droplet on Mac OS X, paste this into a new script and save it as an application:

on open thefiles
  repeat with thefile in thefiles
    set finalpath to POSIX path of thefile
    do shell script "mktemp -t image"
    set temppath to the result
    set success to false
      do shell script "/usr/local/bin/convert '" & finalpath & "' -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 '" & temppath & "'"
      set success to true
    on error theerror
      display dialog "Conversion failed: " & theerror
    end try
    if success then
      do shell script "mv '" & temppath & "' '" & finalpath & "'"
      display notification "Converted " & finalpath
    end if
  end repeat
end open

didymu5 commented Apr 4, 2014

this is so cool! i'm going to introduce my wife to this.

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 \




That's great !

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.

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


delegans commented May 7, 2014

Web service: upload and clean white board on-line

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

Thank you! Works great :)

Checkout this new service . 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 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!

Great work.

amn41 commented Sep 14, 2016

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

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/': 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.

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).

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