Skip to content

@lelandbatey /whiteboardCleaner.md
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

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

@tekknolagi

Definitely make it into a bash/zsh alias :)

@jacobsmith

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

This is great. Well done.

@johndeng

So great. I love it.

@magus

Not experiencing the same results with the same example images.

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

ex1-clean.jpeg

@richrines

Unreal, well done.

@lelandbatey
Owner

@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

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: http://espen.bagateller.com/whiteboardcleaner/1s.jpg
ImageMagick 6.7.7-10 2014-03-06 Q16

@ghost
Unknown commented

Good work, thanks for sharing!

@lsandeep83

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

Original: https://twitter.com/sanlaxman/status/450964599727083520/photo/1

Output: https://twitter.com/sanlaxman/status/451620563958505472/photo/1

@mikaa123

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

@vibragiel

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

@lelandbatey
Owner

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

Input1

Input2

Output1

Output2

@xpepper

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

@apetrov

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
}

@SNaushadS

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

@artumi-richard

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

http://pngquant.org/

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

@marcaube

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

@rylwin

awesome

@silvansky

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

@bensquire

Works a treat :D

@Intrepidd

It's also nice for selfies :)

http://i.imgur.com/uHoPvin.jpg

@ff-apujari

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

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
    try
      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

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

@kinduff

@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

Amazing!

@LucasArruda

Amazing!

@anthonyray

That's great !

@sourcegate

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.

@ShivendraAgrawal

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

@captainpete

Incredible!!

@delegans

Web service: upload and clean white board on-line

http://api.o2b.ru/whiteboardcleaner

@m-space

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

Thank you! Works great :)

@projectdevan

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

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.