Cleaning Up Whiteboard Photos with a Bash Script
Today I created a bash script that automates the cleanup of whiteboard photos. It uses AutoTrace and ImageMagick to convert messy photos into clear, professional-looking diagrams.
The Script
#!/bin/bash
# Input validation
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_image>"
exit 1
fi
input_image="$1"
output_svg="${input_image%.*}.svg"
output_png="${input_image%.*}_cleaned.png"
# Check if input file exists
if [ ! -f "$input_image" ]; then
echo "Error: Input file not found: $input_image"
exit 1
fi
# Preprocessing: Enhance contrast and remove noise
convert "$input_image" -normalize -sharpen 0x1 -despeckle "$input_image"
# Run autotrace with optimized parameters
autotrace \
--dpi 1200 \
--line-threshold 0.05 \
--color-count 8 \
--corner-always-threshold 70 \
--line-reversion-threshold 0.05 \
--width-weight-factor 0.05 \
--despeckle-level 15 \
--despeckle-tightness 3 \
--preserve-width \
--remove-adjacent-corners \
--background-color FFFFFF \
--output-format svg \
--output-file "$output_svg" \
"$input_image"
# Convert SVG to PNG using ImageMagick
convert -density 300 "$output_svg" "$output_png"
echo "Cleaned image saved as: $output_png"
echo "SVG version saved as: $output_svg"
How It Works
- Preprocesses the image to enhance contrast and reduce noise.
- Uses AutoTrace to vectorize the image with optimized parameters.
- Converts the resulting SVG back to a high-resolution PNG.
Usage
- Save as
clean_whiteboard.sh
- Make executable:
chmod +x clean_whiteboard.sh
- Run:
./clean_whiteboard.sh my_whiteboard_photo.jpg
This script significantly improves the clarity of whiteboard photos, making it easier to preserve and share ideas from brainstorming sessions.