Home / Alt manpages / pammixmulti(1)

  • pammixmulti(1)
  • User command
  • linux

Blend PAM Images with pammixmulti Without Losing Your Inputs

pammixmulti combines two or more Netpbm images into one, by averaging, random pixel choice, or a greyscale mask. This guide covers all three, and the command reads its inputs and writes the result to standard output, so nothing you feed it is ever changed. Allow about fifteen minutes if the images and mask already exist.

You need Linux, the Netpbm package, readable input images with matching dimensions, and enough disk space for the output. This guide uses Netpbm 11.5.2 from package netpbm version 2:11.05.02-1.1build1. None of this needs sudo.

1. Check the installed command

Confirm which executable your shell will run and record the local Netpbm version:

$ command -v pammixmulti
/usr/bin/pammixmulti
$ pammixmulti --version
pammixmulti: Using libnetpbm from Netpbm Version: Netpbm 11.5.2

The version output carries build details after the version line. A different release may report different diagnostics, so check man pammixmulti on the machine where a script will actually run.

Checkpoint

You should have the command path and a version number before choosing options.

2. Average corresponding pixels

With no --blend option, pammixmulti uses average: it averages the corresponding pixels from every input. Put the output in a new file, since shell redirection truncates an existing destination before the program starts.

$ pammixmulti /path/to/one.ppm /path/to/two.ppm > blended.ppm
$ file blended.ppm
blended.ppm: Netpbm image data, size = ...

For a group of files, a shell glob expands to separate arguments:

$ pammixmulti frames/frame-*.ppm > frames-average.ppm

Check the glob first if the filenames come from an unfamiliar directory. A pattern that matches nothing can be passed through literally, depending on the shell, and pammixmulti will then fail with an input error.

Use file, a Netpbm reader, or an image viewer to confirm the output exists, has the expected dimensions, and looks right. A successful exit status only proves the command completed, not that the files you selected were the images you intended.

3. Select a source pixel at random

Use --blend=random when each output pixel should come from one of the corresponding input pixels rather than being averaged. This can preserve sharp detail, but the result changes between runs unless you set a seed:

$ pammixmulti --blend=random --randomseed 7 \
    /path/to/one.ppm /path/to/two.ppm > random-7.ppm
$ file random-7.ppm
random-7.ppm: Netpbm image data, size = ...

--randomseed controls the random generator this mode uses. Repeating the same command with the same inputs and seed should produce the same bytes on this installed version:

$ pammixmulti --blend=random --randomseed 7 /path/to/one.ppm /path/to/two.ppm > random-7-again.ppm
$ sha256sum random-7.ppm random-7-again.ppm
...  random-7.ppm
...  random-7-again.ppm

Do not treat the seed as a security control. It makes an image-processing run repeatable; it does not provide cryptographic randomness.

4. Use a greyscale mask

Mask mode uses another image to decide how the input images contribute at each position. Supply --blend=mask and --maskfile together:

$ pammixmulti --blend=mask \
    --maskfile=/path/to/mask.pgm \
    /path/to/one.pam /path/to/two.pam > masked.pam
$ file masked.pam
masked.pam: Netpbm PAM image file, size = ...

The mask must have the same dimensions as the input images. Black selects the first image, white selects the last, and intermediate greys select positions between them. If the mask has multiple channels, pammixmulti treats its first channel as greyscale.

For more than two inputs, the mask range spreads across the ordered input list, which means changing the order changes the meaning of the same mask. Keep the input order explicit in scripts rather than relying on a broad glob when order matters.

The default --stdev is 0.25. Set it to zero for sharper bands:

$ pammixmulti --blend=mask --maskfile=/path/to/mask.pgm --stdev=0.0 \
    /path/to/one.pam /path/to/two.pam /path/to/three.pam > masked-hard.pam

A positive value makes neighbouring images overlap more smoothly, and values approaching the number of input images push the result towards a plain average. Try 1.0 for a visibly gentler transition, then inspect the output rather than assuming a particular visual effect.

Checkpoint

Verify the mask dimensions match before diagnosing a surprising blend. A wrong-size mask is rejected and leaves an empty redirected file.

5. Protect an existing output

Warning

> output.ppm destroys the previous contents of output.ppm immediately. Use a new temporary name, then move it into place only after checking the result:

$ pammixmulti /path/to/one.ppm /path/to/two.ppm > output.ppm.new
$ file output.ppm.new
$ mv output.ppm.new output.ppm

The mv step replaces the old output. If the command or inspection fails, remove only the incomplete output.ppm.new and the original output remains:

$ rm output.ppm.new

That removal is irreversible, so check the name with ls -l first. Keep the original input images until the new result has been inspected.

Common traps

  • Only one input. The program needs two or more images. Check the expanded file list before running a batch.
  • Different dimensions. Resize or otherwise prepare the inputs first; a mask also needs matching dimensions.
  • Unexpected mask behaviour. Confirm the mask is greyscale, or that its first channel carries the intended values. Black and white select opposite ends of the ordered input list.
  • Empty output after an error. That is a direct consequence of redirection. Remove the failed new file and rerun with a corrected command.
  • Unwanted option interaction. --maskfile only applies with mask blending. With the default average mode, the installed command reports that it is ignoring the mask file.

Options may use a single hyphen, may be abbreviated to a unique prefix, and may use whitespace instead of the equals sign. Full long options are clearer in scripts, so use them in new examples and automation.

Done means

  • Command confirmed. command -v pammixmulti finds the intended executable.
  • Dimensions match. The input list and any mask have matching dimensions.
  • Blend mode deliberate. You selected average, random, or mask on purpose.
  • Randomness reproducible when a seeded run actually needs to be repeatable.
  • Output inspected. It exists, has the expected format and dimensions, and has been checked.
  • No input overwritten accidentally.