LinuxCommandLibrary

pgmnoise

Add random noise to PGM image

TLDR

Generate a PGM image containing white noise

$ pgmnoise [width] [height] > [path/to/output.pgm]
copy

Specify the seed for the pseudo-random number generator
$ pgmnoise [width] [height] -randomseed [value] > [path/to/output.pgm]
copy

SYNOPSIS

pgmnoise [-random | -gauss | -uniform | -saltandpepper]
[-value=f] [-threshold=f] [-randomseed=n]
[-nlines=n] [-ncols=n] [-x=n] [-y=n]
[-width=n] [-height=n] [-verbose] [-plain] [pgmfile]

PARAMETERS

-random
    Adds random white noise to the image. This is the default if no noise type is specified.

-gauss
    Adds Gaussian (normally distributed) noise to the image.

-uniform
    Adds uniform noise, where noise values are evenly distributed within a range.

-saltandpepper
    Adds salt-and-pepper noise, introducing extreme pixel values (pure black or white).

-value=f
    Specifies the maximum absolute value of the noise to be added. Its interpretation depends on the noise type.

-threshold=f
    Used with -saltandpepper noise to set the probability threshold (from 0 to 1) for a pixel becoming 'salt' or 'pepper'.

-randomseed=n
    Sets the seed for the random number generator, allowing for reproducible noise patterns.

-nlines=n
    Specifies the number of lines (rows) in the image to apply noise to.

-ncols=n
    Specifies the number of columns in the image to apply noise to.

-x=n
    Specifies the x-coordinate (column) of the top-left corner of the rectangular region where noise will be applied.

-y=n
    Specifies the y-coordinate (row) of the top-left corner of the rectangular region where noise will be applied.

-width=n
    Specifies the width of the rectangular region for noise application.

-height=n
    Specifies the height of the rectangular region for noise application.

-verbose
    Prints informative messages about the noise generation process to standard error.

-plain
    Outputs the resulting PGM image in plain (ASCII) format, which is human-readable but larger in size.

pgmfile
    The path to the PGM image file to be processed. If omitted, pgmnoise reads from standard input.

DESCRIPTION

pgmnoise is a utility from the Netpbm image manipulation toolkit that adds various types of noise to a Portable Graymap (PGM) image. It can generate random, Gaussian, uniform, or salt-and-pepper noise. Users can specify the intensity of the noise, the threshold for salt-and-pepper, and even a specific rectangular region within the image to apply the noise. This command is often used for testing image processing algorithms, simulating real-world image degradation, or creating artistic effects. It reads a PGM image from standard input or a specified file and writes the modified PGM image to standard output.

CAVEATS

  • pgmnoise operates exclusively on PGM (Portable Graymap) images. It cannot directly process PPM (Portable Pixmap) or PBM (Portable BitMap) images.
  • Only one noise type option (-random, -gauss, -uniform, or -saltandpepper) can be specified at a time. The default is -random if none are provided.
  • The interpretation and effect of the -value and -threshold options vary significantly based on the chosen noise type.

INPUT/OUTPUT

pgmnoise typically reads its input PGM image from standard input if no file argument is provided. The resulting noisy PGM image is always written to standard output. This design allows for easy piping with other Netpbm commands, such as
cat image.pgm | pgmnoise -gauss | pgmtopng > noisy.png.

NOISE CHARACTERISTICS

Different noise types have distinct characteristics. Random noise applies independent random values to each pixel. Gaussian noise generates values following a normal distribution, often used to simulate sensor noise. Uniform noise distributes values evenly within a range. Salt-and-pepper noise introduces extreme values (pure black or pure white pixels) at random locations, commonly simulating impulse noise. The -value option controls the magnitude of the noise, while -threshold is specific to salt-and-pepper noise, determining the probability of a pixel becoming salt or pepper.

HISTORY

pgmnoise is an integral part of the Netpbm project, a long-standing open-source toolkit for graphics manipulation. Netpbm originated from Jef Poskanzer's PBMPlus package in the late 1980s, which provided tools for converting between various graphics formats and a simple, extensible set of image formats (PBM, PGM, PPM). pgmnoise embodies the Unix philosophy of small, specialized tools that do one thing well, making it a foundational component for basic image noise operations within this ecosystem.

SEE ALSO

pgm(5), ppm(5), pbm(5), pnm(1), pnmnoise(1), pamnoise(1), pnmgamma(1)

Copied to clipboard