LinuxCommandLibrary

pamdeinterlace

Deinterlace video images

TLDR

Produce an image consisting of the input's even-numbered rows

$ pamdeinterlace [path/to/image.ppm] > [path/to/output.ppm]
copy

Produce an image consisting of the input's odd-numbered rows
$ pamdeinterlace [[-takeo|-takeodd]] [path/to/image.ppm] > [path/to/output.ppm]
copy

SYNOPSIS

pamdeinterlace [-odd | -even | -half] [-interp [-interleave_option=METHOD]] [-top | -bottom] [-topbottom | -bottomtop] [-pair] [-interleave | -interleavefirst | -interleavesecond] [-verbose] [pamfile]

PARAMETERS

-odd
    Output only the odd-numbered scanlines. The resulting image will be half the height of the input.

-even
    Output only the even-numbered scanlines. The resulting image will be half the height of the input.

-half
    A synonym for -odd.

-interp
    Deinterlaces the image by interpolating the missing lines to restore the original height. This creates a progressively scanned image from interlaced fields. This is mutually exclusive with -odd, -even, -half, -pair, and -interleave.

-interleave_option=METHOD
    Specifies the interpolation method to use with -interp. Common methods include "blend" (default), "duplicate", "average", "linear", "top", "bottom", "mean", and "median".

-top
    Assumes the top field of the interlaced image is composed of the odd scanlines (default behavior).

-bottom
    Assumes the bottom field of the interlaced image is composed of the odd scanlines.

-topbottom
    Outputs two fields stacked vertically, with the top field (odd scanlines by default) above the bottom field (even scanlines by default).

-bottomtop
    Outputs two fields stacked vertically, with the bottom field (even scanlines by default) above the top field (odd scanlines by default).

-pair
    Writes two separate PAM files to standard output, one for each field. This requires the output to be redirected to a file, and a second file will be created with a ".1" suffix.

-interleave
    Combines the two fields into a full-height image by interleaving them. By default, it starts with the first field. This is mutually exclusive with -interp, -odd, -even, -half, and -pair.

-interleavefirst
    A synonym for -interleave.

-interleavesecond
    Combines the two fields into a full-height image by interleaving them, starting with the second field.

-verbose
    Prints informational messages about the processing to standard error.

pamfile
    The input PAM or PGM file. If omitted, pamdeinterlace reads from standard input.

DESCRIPTION

pamdeinterlace is a Netpbm command-line utility designed to process interlaced images, typically derived from video sources. It operates on PAM (Portable Arbitrary Map) or PGM (Portable Graymap) formatted images, reading from standard input and writing to standard output. The primary function is to deinterlace an image by separating its odd and even scanlines, which represent the two interlaced fields of a video frame.

It can output a single field (reducing height by half), or it can reconstruct a full-height, progressively scanned image by interpolating the missing lines. Various interpolation methods are available, such as blending, averaging, or duplicating adjacent lines, to achieve different visual qualities for the deinterlaced output. It also offers options to re-interleave fields in various orders or extract fields as separate images. This tool is fundamental for preparing video frames for progressive display or further processing where interlacing artifacts need to be removed.

CAVEATS

The command assumes a specific interlacing pattern (e.g., odd lines form one field, even lines form another). If the source material uses a different or more complex interlacing scheme (e.g., progressive scan within fields, pulldown), pamdeinterlace might not produce optimal results.
When using -pair, the output is two files, which might not be compatible with standard piping mechanisms to other Netpbm tools that expect a single output.
Interpolation methods vary in quality. Simple methods like "duplicate" can cause comb artifacts, while more complex methods like "linear" or "blend" provide smoother transitions but can blur details.

<I>TYPICAL USE CASE</I>

A common usage involves piping an image, possibly extracted from video, into pamdeinterlace with the -interp option to create a visually deinterlaced image for progressive display. For example,
ffmpeg -i video.mp4 -vf select='eq(n,100)' -vframes 1 output.ppm | pamdeinterlace -interp -interleave_option=blend > deinterlaced_frame.ppm
would extract frame 100, then deinterlace it using blending.

<I>FIELD ORDER</I>

Understanding the field order (which field is odd or even, top or bottom) is crucial for correct deinterlacing. Video standards (like NTSC or PAL) often define a specific field dominance. If the default -top assumption is incorrect for your source, you may need to use -bottom to avoid artifacts.

HISTORY

pamdeinterlace is part of the Netpbm project, a long-standing open-source suite of graphics programs for converting and manipulating images. Netpbm itself originated from Jef Poskanzer's Pbmplus package in the late 1980s. pamdeinterlace specifically was written by Bryan Henderson, the current maintainer of Netpbm, and added to the suite to address the common need for deinterlacing video frames processed as images.

SEE ALSO

pam(5), pgm(5), ppm(5), netpbm(1), ffmpeg(1)

Copied to clipboard