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 [-exact] [-color color | -colorname colorname] [ppmfile]

PARAMETERS

-exact
    Masks only pixels that *exactly* match the specified color, with no tolerance for minor variations in color components. By default, there's a tolerance of one Netpbm quantum per color component.

-color color
    Specifies the target color to mask. color can be a color name (e.g., "red", "blue"), a hexadecimal RGB value (e.g., "#FF0000"), or a triplet of numbers representing R, G, B values (e.g., "255,0,0"). If this option is not used, the default color is red.

-colorname colorname
    An alias for -color. This option is provided for backward compatibility.

ppmfile
    The path to the input PPM image file. If not provided, ppmcolormask reads from standard input (stdin).

DESCRIPTION

ppmcolormask is a command-line utility from the Netpbm image manipulation toolkit. It reads a Portable Pixmap (PPM) image as input and generates a Portable Graymap (PGM) image as output. The output PGM image serves as a mask: pixels in the original PPM image that match a specified color are rendered as pure white (maximum intensity) in the PGM mask, while all other pixels are rendered as pure black (zero intensity). This utility is particularly useful for tasks like chroma keying or creating alpha masks for image compositing, where you need to isolate specific color regions.

By default, ppmcolormask looks for the color red, but users can specify any desired color using various formats, including color names, hexadecimal RGB values, or numeric triplets. Unless the -exact option is used, the command allows for a small tolerance in color matching, considering pixels within one Netpbm quantum of each color component as a match.

CAVEATS

The default color matching has a tolerance of one Netpbm quantum per component. For precise matching, always use the -exact option. Color names are system-dependent and rely on the `rgb.txt` file; using hexadecimal or numeric triplets is more portable for defining colors.

INPUT/OUTPUT

ppmcolormask expects a PPM image as input and produces a PGM image as output. Both can be read from and written to standard input/output respectively, enabling easy piping with other Netpbm tools for chained operations.

COLOR SPECIFICATION

When specifying colors with -color or -colorname, Netpbm uses the `rgb.txt` database for color names. If a name is not found, or for more precise control, hexadecimal RGB values (`#RRGGBB`) or comma-separated decimal triplets (`R,G,B`) can be used to define the color.

HISTORY

ppmcolormask is an integral part of the Netpbm project, a widely used suite of graphics file format converters and image processing tools. Netpbm originated from Jef Poskanzer's PBMplus package in the late 1980s. This utility, like other Netpbm tools, adheres to the philosophy of simple, single-purpose commands that can be piped together to achieve complex image manipulations. Its ongoing development as part of the larger Netpbm codebase ensures continued compatibility and utility for various image processing tasks on Unix-like systems.

SEE ALSO

ppmcolor(1), ppmmake(1), ppm(5), pgm(5), netpbm(1)

Copied to clipboard