Skip to content

@lelandbatey /
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
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


This is great. Well done.


So great. I love it.


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.


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


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

Unknown commented

Good work, thanks for sharing!


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




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.


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






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.


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.


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




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; }


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

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


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




Web service: upload and clean white board on-line


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


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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.