Home / Alt manpages / pamdeinterlace(1)

  • pamdeinterlace(1)
  • User command
  • linux

Remove Interlaced Rows from a Netpbm Image with pamdeinterlace

You will finish with a repeatable way to keep alternate rows from a PAM or PNM image, check that the output has the expected height, and optionally restore that height with a Netpbm scaler. This is useful for a frame captured from an interlaced video source where adjacent rows represent different moments in time.

Allow about fifteen minutes. You need the Netpbm package, a readable PAM or PNM input, and enough space for a new output file. The examples use the installed Debian package netpbm 2:11.05.02-1.1build1, whose command reports Netpbm 11.5.2. No step needs sudo. Keep the original image until you have checked the result.

1. Check the installed command

Confirm the executable and package version before relying on a script or a result. These are ordinary, read-only commands:

$ command -v pamdeinterlace
/usr/bin/pamdeinterlace
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pamdeinterlace --version
pamdeinterlace: Using libnetpbm from Netpbm Version: Netpbm 11.5.2

The version output also includes build details on this installation. The useful compatibility point is that this guide describes the command supplied by Netpbm 11.5.2. If your package is older or newer, read its local pamdeinterlace(1) page before putting the command into a batch job.

Checkpoint

You have a readable input image and know which Netpbm installation will process it.

2. Understand which rows are kept

pamdeinterlace removes half of the input rows. By default it keeps the even-numbered rows, with numbering starting at zero. That means input row 0 becomes output row 0, input row 2 becomes output row 1, and so on. The output is therefore half the input height, rounded according to the program's row processing.

Use -takeodd to keep odd-numbered rows instead. In that mode, the first output row comes from input row 1. The options are choices, not filters that can be combined: specifying both -takeeven and -takeodd is an error. The command accepts the shortest unique option abbreviation, but full names make a script easier to review. It also accepts two hyphens in place of one, although the examples use the documented single-hyphen form.

3. Make a safe test image

If you want to verify the row choice before touching a real image, create a small temporary PGM. This writes a new file in the current directory and does not alter an existing image unless you choose its name deliberately:

$ cat > rows.pgm <<'EOF'
P2
2 4
255
10 11
20 21
30 31
40 41
EOF
$ pnmfile rows.pgm
rows.pgm: PGM raw, 2 by 4

The four rows are easy to distinguish. The default selection should retain the values from rows 0 and 2: 10 11 and 30 31. The odd selection should retain rows 1 and 3: 20 21 and 40 41.

Checkpoint

pnmfile reports a 2 by 4 input. If it reports an error, fix the input format before diagnosing pamdeinterlace.

4. Write the even-row output

Use shell redirection to create a different destination. The source is read from the named argument and the processed image is written to standard output:

$ pamdeinterlace rows.pgm > rows-even.pgm
$ pnmfile rows-even.pgm
rows-even.pgm: PGM raw, 2 by 2

This command uses the default -takeeven behaviour. A successful exit status and the reported 2 by 2 dimensions confirm that the image was reduced to half its original height. To select odd-numbered rows, name a separate output:

$ pamdeinterlace -takeodd rows.pgm > rows-odd.pgm
$ pnmfile rows-odd.pgm
rows-odd.pgm: PGM raw, 2 by 2

On this installation, the output is reported as raw PGM even when the input test file is plain-text PGM. That is normal Netpbm output conversion, not a row-selection failure. The input format and output format can be inspected with pnmfile.

5. Process a real image without losing it

Do not redirect directly over the source. The shell opens and truncates the destination before the program finishes, so a typo or failed conversion can destroy an existing output. Choose a new name, or use a temporary file followed by a deliberate replacement:

$ pamdeinterlace -takeeven /path/to/capture.ppm > /path/to/capture-deinterlaced.ppm.tmp
$ pnmfile /path/to/capture-deinterlaced.ppm.tmp
/path/to/capture-deinterlaced.ppm.tmp: PPM raw, 1920 by 540
$ mv /path/to/capture-deinterlaced.ppm.tmp /path/to/capture-deinterlaced.ppm

Replace the example path and dimensions with values for your image. The mv is only appropriate after the verification command succeeds. If processing fails, remove the temporary file and the source remains available:

$ rm /path/to/capture-deinterlaced.ppm.tmp

That removal is irreversible for the temporary output, so check the path before pressing Enter. It does not remove the original capture.

6. Restore the display height when needed

The row-removal step deliberately produces a half-height image. If you need the original display height, pipe the output to pamstretch with a vertical scale of two:

$ pamdeinterlace -takeeven /path/to/capture.ppm \
    | pamstretch -yscale=2 > /path/to/capture-deinterlaced-full-height.ppm
$ pnmfile /path/to/capture-deinterlaced-full-height.ppm
/path/to/capture-deinterlaced-full-height.ppm: PPM raw, 1920 by 1080

This restores the pixel height, but it does not recreate the missing temporal information. For some material, the Netpbm manual identifies pammixinterlace as a usually better deinterlacing approach because it combines information from both fields. Treat that as a separate operation and compare its output rather than replacing a known-good file blindly.

7. Diagnose the common failures

If the command cannot open the input, check the path and permissions without changing the image:

$ ls -l /path/to/capture.ppm
$ test -r /path/to/capture.ppm && echo readable

If both row options are supplied, the command exits non-zero and reports that they cannot be used together. Pick one and rerun. If the output is the wrong height, first confirm that the input dimensions are what you think with pnmfile; a viewer's scaling is not a reliable measurement.

A successful command only proves that Netpbm produced an image. It does not prove that you selected the visually better field. Open both even and odd results, where practical, and keep the original until the motion and detail look right. For a production pipeline, preserve the non-zero exit status of either stage in a pipe and write to a new destination.

Done means

  • The installed Netpbm version and local command path are known.
  • You chose -takeeven or -takeodd deliberately, knowing that rows start at zero.
  • The output dimensions were checked with pnmfile and are half the source height unless a later scaler was used.
  • The source image was not overwritten during testing or recovery.
  • Any full-height output was produced as a separate file and checked before use.