pgmenhance
Improve contrast of PGM image files
TLDR
Edge-enhance a PGM image
Specify the level of enhancement
SYNOPSIS
pgmenhance [inputfile [outputfile]]
DESCRIPTION
pgmenhance is a utility from the Netpbm graphics suite that improves the quality of portable grayscale map (PGM) images by applying an unsharp masking algorithm.
It works by first creating a blurred (low-pass filtered) version of the input image using a simple 3x3 averaging kernel. This blurred image is then subtracted from the original, amplified by a fixed factor (typically around 1.5), and added back to the original. The result accentuates edges and fine details, boosting perceived sharpness and contrast without altering the image dimensions or color depth.
This technique is particularly effective for softening out-of-focus images, scanned documents, or low-contrast photos. However, it can amplify noise or grain in already sharp or noisy inputs.
The program reads PGM input from stdin or a file and writes enhanced PGM output to stdout or a file. It is lossless in terms of format compatibility but irreversible due to the nonlinear processing. For color images, use pamenhance instead.
All parameters are fixed internally, making it simple but less flexible than convolution-based tools.
CAVEATS
No adjustable parameters for enhancement strength; fixed algorithm may oversharpen noisy images or underperform on high-contrast inputs. Strictly for PGM (grayscale); use pamenhance for PAM/PPM.
EXAMPLE USAGE
pgmenhance scan.pgm > enhanced.pgm
Reads scan.pgm, enhances it, and writes to enhanced.pgm.
ALGORITHM NOTE
Uses fixed unsharp mask: enhanced = original + 1.5 × (original - 3×3 average blur).
HISTORY
Originated in Jef Poskanzer's PBMPLUS toolkit (late 1980s), integrated into Netpbm around 1991. Maintained with minor tweaks for portability; unchanged core algorithm since inception.


