LinuxCommandLibrary

ppmmix

Mix portable pixmap (PPM) image files

TLDR

Blend the specified PPM images using fadefactor to control the weight of each image

$ ppmmix [fadefactor] [path/to/input_file1.ppm path/to/input_file2.ppm ...] > [path/to/output_file.ppm]
copy

SYNOPSIS

ppmmix [options] [image1_file] [image2_file]

Reads two Portable Pixmap (PPM) images from files or standard input and writes the blended PPM image to standard output.

PARAMETERS

image1_file
    The path to the first Portable Pixmap (PPM) image to be blended. If omitted, the first image is read from standard input.

image2_file
    The path to the second Portable Pixmap (PPM) image to be blended. If omitted, the second image is read from standard input after the first.

-weight n
    Specifies a constant floating-point weight for the mix, where n is a value between 0.0 and 1.0. A value of 0.0 means only the first image is visible, and 1.0 means only the second. This option takes precedence over -alphafile and -alphaval.

-alphafile alpha_file
    Specifies a Portable Graymap (PGM) file to use as a per-pixel alpha mask. The grayscale values in alpha_file determine the blend ratio for each corresponding pixel. This file must have the same dimensions as the input images. This option takes precedence over -alphaval.

-alphaval alpha_val
    Specifies a constant integer alpha value between 0 and the input images' maxval. This value determines the blend ratio for all pixels. 0 means image1 is fully visible, maxval means image2 is fully visible.

DESCRIPTION

ppmmix is a Netpbm utility designed to blend two Portable Pixmap (PPM) images together. It takes two input images of the same dimensions and maximum color value (maxval) and produces a single blended PPM image as output. The blending process applies a formula: new_pixel = (pixel1 * (1 - alpha)) + (pixel2 * alpha). The 'alpha' value, which determines the blending ratio, can be specified globally via a constant weight or integer value, or on a per-pixel basis using a separate Portable Graymap (PGM) alpha mask file. If no alpha source is provided, ppmmix defaults to an even 50/50 mix. This tool is fundamental for creating effects like image fading, transparency, or combining visual elements in a compositing workflow.

CAVEATS

Input Image Requirements:
Both input PPM images must have identical dimensions (width and height) and the same maximum color value (maxval). Failure to meet these requirements will result in an error.

Alpha File Requirements:
If using the -alphafile option, the specified PGM file must also have the exact same dimensions as the input images.

Option Precedence:
Only one alpha source option (-weight, -alphafile, or -alphaval) can be used at a time. If multiple are provided, -weight takes highest precedence, followed by -alphafile, then -alphaval.

BLENDING FORMULA

The core of ppmmix's operation is its blending formula: new_pixel = (pixel1 * (1 - alpha)) + (pixel2 * alpha).

Here:
new_pixel represents the resulting pixel value in the output image.
pixel1 and pixel2 are the corresponding pixel values from the first and second input images.
alpha is the blending factor, which can be a constant derived from -weight or -alphaval, or a per-pixel value from -alphafile.

DEFAULT BEHAVIOR

If no alpha source option (-weight, -alphafile, or -alphaval) is specified, ppmmix defaults to an alpha value of 0.5. This results in an equal 50/50 blend between the two input images, effectively averaging their pixel values.

HISTORY

ppmmix is a component of the Netpbm project, a comprehensive suite of graphics utilities for image manipulation. Netpbm originated from the PBMplus package, developed in the late 1980s by Jef Poskanzer. The philosophy behind Netpbm tools like ppmmix is to provide small, efficient, and specialized programs that can be chained together via pipes to perform complex image processing tasks. This modular approach emphasizes interoperability and command-line automation, a hallmark of traditional Unix tool design.

SEE ALSO

pnmblend(1), pnmgamma(1), pamstack(1), convert(1), composite(1)

Copied to clipboard