Home / Alt manpages / pambayer(1)

  • pambayer(1)
  • User command
  • linux

Turn a Raw Bayer Plane into PAM RGB with pambayer

You will finish with a PAM RGB image made from a one-plane Bayer sensor image, while leaving the source file untouched. The examples use pambayer from Netpbm package version 2:11.05.02-1.1build1 on this machine. Allow about fifteen minutes if the input is ready, or longer if you still need to identify the camera's sensor layout.

You need Netpbm and a pseudo-PNM or PAM file containing one sample plane per sensor position. This is not a general raw-camera decoder: the input must already be represented as a Netpbm-style image, and the Bayer arrangement must be known. No elevated privileges are needed.

1. Check the installed command

Confirm that the command and package are present before working on an image:

$ command -v pambayer
/usr/bin/pambayer
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

The version line is machine-specific. If your distribution reports another Netpbm version, read its local pambayer(1) page before relying on a newer or older option.

Checkpoint: if command -v prints nothing, stop here and install Netpbm through your normal package-management process. Do not download a replacement binary into a directory in your image-processing path.

2. Identify the Bayer arrangement

The mandatory -type option tells pambayer which colour is at each position in the repeating two-by-two pattern. The four values are not quality settings; choosing the wrong one swaps or shifts colours throughout the image.

ValuePattern shown by the manpageTop-left sensor
1GBG/RGR/GBGgreen
2RGR/GBG/RGRred
3BGB/GRG/BGBblue
4GRG/BGB/GRGgreen

Use the value documented for the camera or for the conversion that produced the pseudo-PNM file. Do not infer it from the filename. A common distraction is to treat -type=1 as a default: there is no default, and this option is mandatory.

3. Convert with interpolation

Run the conversion into a new file. Replace the example paths and choose the verified pattern value:

$ pambayer -type=2 camera-bayer.pam > camera-rgb.pam
$ pamfile camera-rgb.pam
camera-rgb.pam: PAM, 4000 by 3000 by 3 maxval 4095
    Tuple type: RGB

The dimensions and maximum value in the verification output depend on the input. The useful invariants are depth 3 and tuple type RGB. pambayer produces one output pixel for each sensor position. At positions where two colour components are absent from the Bayer input, its normal mode estimates them by averaging adjacent samples that contain those components.

That averaging is interpolation, not a recovery of measurements that the sensor made. It makes a viewable colour image, but the result still depends on the selected pattern and on the edge behaviour of the input. Keep the original camera-bayer.pam as the source of record.

Checkpoint: if pamfile says the result is not a three-plane RGB PAM image, stop before opening or converting it further. Check the input format and the -type value first.

4. Make a sparse, non-interpolated representation

For analysis where you want the measured colour samples and not estimates, add -nointerpolate:

$ pambayer -type=2 -nointerpolate camera-bayer.pam > camera-samples.pam
$ pamfile camera-samples.pam
camera-samples.pam: PAM, 4000 by 3000 by 3 maxval 4095
    Tuple type: RGB

The output still has RGB depth and the same dimensions, but each pixel contains only the component supplied by its corresponding sensor position. The other two components are zero. This can look very dark or patterned when displayed; that appearance is expected and is not evidence that the conversion failed.

The option was added in Netpbm 10.49, according to the installed manpage. It is therefore available in the installed 2:11.05.02 package, but scripts intended for older Netpbm installations should check the target version rather than assuming it exists.

5. Inspect one colour channel when needed

If you need only a primary colour from the interpolated result, pass the PAM stream to pamchannel. The manpage identifies that as the separate Netpbm tool for channel extraction, so keep this operation distinct from Bayer interpretation:

$ pambayer -type=2 camera-bayer.pam | pamchannel 1 > camera-red.pam
$ pamfile camera-red.pam
camera-red.pam: PAM, 4000 by 3000 by 1 maxval 4095

Channel numbering and the precise pamchannel syntax belong to that command's own manual page. Read it before changing the channel number. If your next tool requires PPM rather than PAM, convert the RGB result with pamtopnm, as recommended by pambayer(1):

$ pambayer -type=2 camera-bayer.pam | pamtopnm > camera-rgb.ppm

These pipelines write to standard output. A failed command can leave a partial destination file if the shell has already opened the redirection target. For important work, write to a temporary name in the same filesystem, verify it with pamfile, then rename it over a deliberately chosen destination. Renaming is a state-changing operation; do not point it at the only copy of the source.

6. Diagnose the common failures

An error about a missing -type value means the invocation is incomplete. Add exactly one of 1, 2, 3 or 4. The program accepts the usual Netpbm option conventions described in its manpage: a double hyphen is allowed, whitespace can replace the equals sign, and a unique option abbreviation may work. Prefer the full option in scripts so that a future option cannot make an abbreviation ambiguous.

An input error usually means the file is not a one-plane Netpbm image, the header does not describe the samples you think it does, or a binary payload was damaged during an earlier conversion. Inspect the header with a suitable Netpbm reader and compare the result with the camera or conversion documentation. Do not repair a suspicious file by changing its header blindly: that changes how every sample is interpreted.

A technically valid but strangely coloured image is most often a wrong Bayer type. Recheck the camera documentation, then repeat the conversion into a different destination. Do not overwrite the first result until you have compared the pattern choice and retained a reproducible command line.

Done means

  • The input is a one-plane pseudo-PNM or PAM image and its Bayer arrangement is documented.
  • The command uses a mandatory, verified -type value.
  • pamfile confirms a three-plane PAM image with tuple type RGB.
  • You used interpolation for a viewable image, or -nointerpolate deliberately for measured sparse samples.
  • The original Bayer file remains unchanged and every destination has been checked before further conversion.