LinuxCommandLibrary

ppmtorgb3

Convert PPM image to RGB rasterfile

TLDR

Separate the color components of a PPM file, saving the outputs to file.red, file.grn and file.blu

$ ppmtorgb3 [path/to/file.ppm]
copy

SYNOPSIS

ppmtorgb3 [ppmfile [redfile [greenfile [bluefile [alphafile]]]]]
ppmtorgb3 -alpha [ppmfile [redfile [greenfile [bluefile [alphafile]]]]]

PARAMETERS

ppmfile
    The input PPM or PAM image file. If omitted or specified as '-', it reads from standard input.

redfile
    The output PGM file for the red color component. If omitted, the red component is written to standard output, concatenated with other components.

greenfile
    The output PGM file for the green color component. If omitted, the green component is written to standard output, concatenated with other components.

bluefile
    The output PGM file for the blue color component. If omitted, the blue component is written to standard output, concatenated with other components.

-alpha
    Enables extraction of the alpha channel. If the input is a PAM image and this option is used, an additional PGM file for the alpha channel is created. If alphafile is not specified, the alpha component is concatenated to standard output after R, G, B.

alphafile
    The output PGM file for the alpha channel. This parameter is only relevant when the -alpha option is used with a PAM input image. If omitted, the alpha component is written to standard output, concatenated with others.

--
    Marks the end of command-line options. Use this if your ppmfile argument begins with a hyphen to prevent it from being interpreted as an option.

DESCRIPTION

ppmtorgb3 is a utility from the Netpbm suite designed to separate a Portable Pixmap (PPM) image into its constituent red, green, and blue color channels. Each channel is output as a separate Portable Graymap (PGM) image, where pixel values represent the intensity of that specific color component.

If the input image is a Portable Arbitrary Map (PAM) and the -alpha option is specified, an additional PGM file representing the alpha transparency channel can also be extracted. This command is primarily used for color channel analysis, manipulating individual color planes, or preparing images for specific processing tasks. Output files can be specified as arguments; otherwise, the components are concatenated sequentially to standard output.

CAVEATS

The command outputs PGM files, which are grayscale. Each PGM file represents the intensity of a single color or alpha channel. When output filenames are omitted, all components are concatenated to standard output; this typically requires further piping or parsing (e.g., using pamstack or multiple invocations with redirection) to truly separate them into individual files.

INPUT/OUTPUT FORMATS

Input is expected to be a Netpbm PPM or PAM image. Output files are Netpbm PGM images, each representing a single color (red, green, blue) or alpha channel.

STANDARD USAGE EXAMPLE

To separate image.ppm into individual red, green, and blue PGM files:
ppmtorgb3 image.ppm red.pgm green.pgm blue.pgm

To extract components including alpha from a PAM image into separate files:
ppmtorgb3 -alpha input.pam red.pgm green.pgm blue.pgm alpha.pgm

To pipe components to other Netpbm tools for further processing (e.g., converting red channel to a different format):
ppmtorgb3 image.ppm | head -n header_lines_red | pgmtojpeg > red.jpg (This example is simplified; actual piping requires careful handling of concatenated PGM headers).

HISTORY

ppmtorgb3 is a part of the Netpbm project, a comprehensive toolkit for graphics file format conversion and manipulation. Netpbm evolved from the PBMPLUS package, originally created by Jef Poskanzer in the late 1980s. This command represents a fundamental operation of color channel separation, a core capability required for various image processing and analysis tasks within the Netpbm ecosystem.

SEE ALSO

rgb3toppm(1), pamchannel(1), ppm(5), pgm(5), pam(5)

Copied to clipboard