What's the best filter for downsampling text?
downsampling, image, imagemagick, resampling, text
Solution
There is no generally-accepted downsampling filter; simply because, there's no generally-accepted type-face for text. You'll need to identify the font(s) your working with, and apply the best-matching filter for said task.
- Processing emails from 2005? Tahoma font => Hermite filter
- Scanned faxes? Mixed high contrast => Point filter
Visual comparision of each filter's stangth & weakness can be found here & here.
I like to remind myself which filter will meet a task by generating a visual cheat-sheet.
Here's a quick bash script previewing "DejaVu Sans Condensed"
#!/bin/bash
# Adjust this to type-face you'd like to preview
FONT_TO_PREVIEW="DejaVu-Sans-Condensed-Bold"
# Create a temp directory to work with
mkdir filter_tmp
cd filter_tmp
while read filter
do
# Generate base file
convert \
-gravity center -font $FONT_TO_PREVIEW -background white -size 126x \
-fill black -pointsize 12 label:$filter $filter.org.png
# Resample
convert $filter.org.png -filter $filter -resize 400% $filter.filter.png
# Crop center
mogrify -gravity center -crop 126x+0+0 +repage $filter.filter.png
# Tile filtered image below original
montage $filter.org.png $filter.filter.png -tile 1x2 -geometry +1+1 +label +set label $filter.png
# Clean house
rm $filter.filter.png $filter.org.png
# Generate list of all installed filters
done < <(identify -list filter)
montage -geometry +4+4 -tile 4x *.png ../filter_preview.png
# Clean house & display generated filter preview
cd ..
rm -rf filter_tmp
display -display :0 filter_preview.png
Problem
I'm using ImageMagick to downsample text. I realize that there's no such thing as the best filter for every situation, but I'm thinking there must be a generally-accepted standard when it comes to downsampling text specifically (I could be wrong). Here's the list of filters available in ImageMagick: - Bartlett - Blackman - Bohman - Box - Catrom - Cubic - Gaussian - Hamming - Hanning - Hermite - Jinc - Kaiser - Lagrange - Lanczos - LanczosSharp - Lanczos2 - Lanczos2Sharp - Mitchell - Parzen - Point - Quadratic - Robidoux - Sinc - SincFast - Triangle - Welsh