Skip to documentation
DocumentationAll documentsEnglish

PIXBGSTRIP(1)

NAME

pixbgstrip - strip a uniform background color from a pix(5) file

On this page

SYNOPSIS

pixbgstrip [-a] [-t _thresh_] [-x _x_offset_] [-s _squaresize_] [-w _width_] [-n _height_] [file.pix]

DESCRIPTION

pixbgstrip reads a pix(5) image from the named file, or from standard input if no file is given, and writes a new pix(5) image to standard output in which the background color has been replaced with black (0/0/0).

For each scanline, the pixel at the background X offset (see -x) is taken as the reference background color. Every pixel on that scanline whose color falls within the matching threshold (see -t) of the reference is set to black; all other pixels are passed through unchanged. This is useful for keying out a solid or smoothly shaded backdrop, such as one produced by pixbackgnd(1), before compositing an image over a new background.

The image dimensions must be known so each scanline can be read. By default the input is assumed to be 512x512 pixels. The dimensions may be set explicitly with -w, -n, and -s, or guessed from the file length with -a.

OPTIONS

-a

Autosize the input. The length of the input file is compared against a table of common image sizes and, if a match is found, the corresponding width is used. Only works when reading from a file, not a pipe.

-t thresh

Set the matching threshold (default 0). A pixel is treated as background only if each of its red, green, and blue channels differs from the reference background pixel by less than thresh. A larger value tolerates a slightly noisy background.

-x x_offset

Set the X offset, in pixels, of the pixel sampled as the background color for each scanline (default 0, the leftmost pixel). Use this when the image has a border so the true background can be sampled instead. The offset must be smaller than the image width.

-s squaresize

Set both the width and height of the input to squaresize pixels. Disables autosizing.

-w width

Set the width, in pixels, of each input scanline. Disables autosizing.

-n height

Set the height, in scanlines, of the input. Disables autosizing. (The program reads until end of file, so this value chiefly serves to turn off autosizing.)

EXAMPLES

Example 1. Key out a rendered background and composite over a new one
rt -o image.pix model.g component.r
pixbgstrip -w 1024 -n 1024 image.pix > stripped.pix
pixmerge -g stripped.pix newbg.pix > composite.pix

A 1024x1024 image is rendered with rt(1), its solid background color is replaced with black by pixbgstrip, and the result is then layered over a replacement backdrop with pixmerge(1) (whose -g option treats black as transparent), yielding a composite image.

Example 2. Strip a slightly noisy bordered background
pixbgstrip -a -x 5 -t 4 frame.pix > clean.pix

The input size is guessed automatically (-a), the background color is sampled five pixels in from the left edge to skip a thin border (-x 5), and a threshold of 4 (-t 4) tolerates minor noise in the background.

SEE ALSO

brlcad(1), pixbackgnd(1), pixmerge(1), pix-fb(1), fb-pix(1), pix(5)

DIAGNOSTICS

If the input file is shorter than a whole number of scanlines, the trailing partial scanline is discarded and the program exits.

AUTHOR

BRL-CAD Team

This software is Copyright (c) 1991-2026 by the United States Government as represented by U.S. Army Research Laboratory.

BUG REPORTS

Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org