LinuxCommandLibrary

ppmcolormask

Mask a PPM image with a color

TLDR

Produce a mask of areas of a certain color in the specified PPM image

$ ppmcolormask [[-c|-color]] [red,blue] [path/to/input.ppm] > [path/to/output.pbm]
copy

SYNOPSIS

ppmcolormask [-tolerance=value] [-maxval=maxval] colorfile [ppmfile]

PARAMETERS

-tolerance=value
    Specify the tolerance to use when comparing colors. A higher tolerance means that colors more different from the specified color will be considered a match. Default is 0.

-maxval=maxval
    Specify the maximum gray value in the output PGM image. Default is the maximum gray value of the PGM format which is 255

colorfile
    The file containing the color to use as the mask color. This file must be a PBM file with exactly one pixel of the color to mask.

ppmfile
    The PPM file to read. If not specified, ppmcolormask reads from standard input.

DESCRIPTION

The ppmcolormask command reads a PPM image as input and creates a PGM (grayscale) mask as output. The mask indicates which pixels in the input image match a specified color. This is useful for isolating specific colored regions within an image for further processing, such as compositing or filtering. The command effectively identifies pixels that are 'close' to the target color based on a user-definable tolerance. The output mask is a PGM image where pixels are white (maximum value) if they match the color (within the tolerance) and black (minimum value) otherwise. This tool is valuable in image manipulation pipelines for isolating image regions by color.

CAVEATS

The colorfile parameter must be a PBM file even if it represents color.

EXAMPLE

To create a mask from 'image.ppm' identifying pixels similar to the color in 'target_color.pbm' with a tolerance of 10, use:
ppmcolormask -tolerance=10 target_color.pbm image.ppm > mask.pgm

This will create a PGM image named 'mask.pgm' containing the mask.

SEE ALSO

ppm(5), pgm(5), pbm(5)

Copied to clipboard