LinuxCommandLibrary

pnmnorm

Normalize Portable Pixmap (PPM) image intensity

TLDR

Force the brightest pixels to be white, the darkest pixels to be black and spread out the ones in between linearly

$ pnmnorm [path/to/image.pnm] > [path/to/output.pnm]
copy

Force the brightest pixels to be white, the darkest pixels to be black and spread out the ones in between quadratically such that pixels with a brightness of n become 50 % bright
$ pnmnorm [[-midv|-midvalue]] [n] [path/to/image.pnm] > [path/to/output.pnm]
copy

Keep the pixels' hue, only modify the brightness
$ pnmnorm [[-k|-keephues]] [path/to/image.pnm] > [path/to/output.pnm]
copy

Specify a method to calculate a pixel's brightness
$ pnmnorm -[luminosity|colorvalue|saturation] [path/to/image.pnm] > [path/to/output.pnm]
copy

SYNOPSIS

pnmnorm [-b blackval] [-w whiteval] [-S saturate] [-l minlumin] [-L maxlumin] [-m maxsamples] [pnmfile]

PARAMETERS

-b blackval
    Specifies the target value for the darkest pixel found in the image.
Instead of mapping the darkest pixel to 0, it will be mapped to blackval (0 to maxval). Defaults to 0.

-w whiteval
    Specifies the target value for the brightest pixel found in the image.
Instead of mapping the brightest pixel to maxval, it will be mapped to whiteval (0 to maxval). Defaults to maxval.

-S saturate
    A percentage (0.0 to 100.0) indicating how much of the darkest and lightest pixels should be "clipped".
For example, if saturate is 1.0, the darkest 1% of pixels will be mapped to the blackval and the brightest 1% to the whiteval, preventing outliers from excessively stretching the contrast.

-l minlumin
    Sets a minimum luminance value to map to blackval.
If the actual darkest pixel in the image is brighter than minlumin, then minlumin is used as the mapping point for black.
This ensures a certain level of darkness is always rendered as black.

-L maxlumin
    Sets a maximum luminance value to map to whiteval.
If the actual brightest pixel in the image is darker than maxlumin, then maxlumin is used as the mapping point for white.
This ensures a certain level of brightness is always rendered as white.

-m maxsamples
    Limits the number of pixels sampled to determine the darkest and brightest values.
This is useful for very large images to speed up processing. The default is 100000 samples.

DESCRIPTION

pnmnorm is a Netpbm utility that enhances the contrast of a PNM image (PBM, PGM, or PPM). It achieves this by "normalizing" the pixel values, meaning it scales the darkest pixel value in the image to black (0) and the lightest pixel value to white (the image's maxval), with all intermediate values linearly adjusted. This process effectively expands the image's dynamic range to fill the entire available color space, making "washed out" or low-contrast images appear more vibrant and defined.

For color (PPM) images, pnmnorm operates on the luminance component of the colors, based on the NTSC standard, and then converts the colors back. For grayscale (PGM) images, it works directly on the gray values. While it does process PBM (bitmap) images, their binary nature often means normalization has little or no visible effect unless specific options are used. The command can read from a specified file or standard input and writes the normalized image to standard output.

CAVEATS

pnmnorm primarily operates on the luminance component for color (PPM) images, which might not always produce the desired perceptual effect on individual color channels.
For PBM (bitmap) images, the effect of pnmnorm is usually negligible or non-existent, as they only contain black and white pixels.
Using the -S option (saturation) can lead to loss of detail in the darkest and brightest regions if the percentage is set too high, as these pixels will be clipped to pure black or pure white.
If the image has a maxval less than 255, pnmnorm will scale the image to a maxval of 255 after normalization, which might change the image's overall range.

INPUT/OUTPUT

pnmnorm reads a PNM image from pnmfile or standard input if no file is specified. The resulting normalized PNM image is written to standard output. This allows for easy piping with other Netpbm commands.

INTERNAL PRECISION

The calculations within pnmnorm are performed using floating-point arithmetic to maintain precision during scaling, ensuring accurate luminance mapping.

HISTORY

pnmnorm is part of the Netpbm project, a widely used open-source graphics toolkit. The Netpbm package evolved from earlier tools like Pbmplus, which was created by Jef Poskanzer in the late 1980s. pnmnorm itself likely appeared early in the development of these tools, as contrast normalization is a fundamental image processing operation. The Netpbm project continues to be actively maintained, providing a robust set of command-line utilities for manipulating image files.

SEE ALSO

pnmhisteq(1), pnmgamma(1), pnmremap(1), netpbm(1), pnm(5)

Copied to clipboard