Home / Alt manpages / pammixmulti(1)

  • pammixmulti(1)
  • User command
  • linux

Blend PAM Images with pammixmulti Without Losing Your Inputs

You will combine two or more Netpbm images into one output using pammixmulti. The examples cover the default average, repeatable random selection, and a greyscale mask that controls a blend. The command reads its inputs and writes the image to standard output, so the inputs are not 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. The installed command used for this guide is Netpbm 11.5.2 from package netpbm version 2:11.05.02-1.1build1. This is ordinary image processing: the commands do not need 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 contains build details after the version line. A different release may have different diagnostics, so check man pammixmulti on the machine where a script will 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; 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 file names come from an unfamiliar directory. A pattern that matches nothing can be passed literally, depending on the shell, and then pammixmulti will fail with an input error.

Use file, a Netpbm reader, or an image viewer to confirm that the output exists, has the expected dimensions, and looks right. A successful exit status proves that the command completed, not that the selected files 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 details, 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 used by this mode. Repeating the same command with the same inputs and seed should produce the same bytes with 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 is spread across the ordered input list. That 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 the 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. Values approaching the number of input images make the result tend towards an average. Try 1.0 for a visibly gentler transition, then inspect the output rather than assuming a particular visual effect.

Checkpoint

Verify that 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.

6. Diagnose the 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 that the mask is greyscale or that its first channel contains the intended values. Black and white select opposite ends of the ordered input list.
  • Output is empty after an error: this is a consequence of redirection. Remove the failed new file and rerun with a corrected command.
  • Unwanted option interaction: --maskfile 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 -v pammixmulti finds the intended executable.
  • The input list and any mask have matching dimensions.
  • You selected average, random, or mask deliberately.
  • A seeded random run is reproducible when reproducibility matters.
  • The output exists, has the expected format and dimensions, and has been inspected.
  • No original input was overwritten accidentally.