PIXMATTE(1)
π PIXMATTE(1) β the BRL-CAD one where you matte two images together
okay so bestie, picture this: it's a pixmatte(1) page from BRL-CAD, and it's literally the glow-up your compositing bag needed. it merges two pix(5) or bw(5) images by a formula. no cap. let's get into it π
β¨ NAME β¨
pixmatte β matte (merge) two pix(5) or bw(5) images by a formula. she's giving "chroma key but make it a whole program" π
π¦ SYNOPSIS π¦
pixmatte [-w _width_in_bytes_] {-g -l -e -n -a} _in1_ _in2_ _true_out_ _false_out_ > _output_
like, yes, that's a lot of args. she's high-maintenance and worth it. π
πΈ DESCRIPTION πΈ
okay so here's the whole vibe. you hand pixmatte four streams of data elements, and each element can be any width you want (typically pix(5) or bw(5) images, iykyk). then it outputs a stream with the same number of data elements. same count, no notes. β¨
the value of the output stream gets decided element-by-element, by comparing the first stream β the foreground in1 β with the second stream β the background, aka the matte, in2. the way that works is:
- if the formula holds true β the element from the
true_outstream gets written π - otherwise β the element from the
false_outstream gets written π«Ά
and because this whole routine works element-by-element, it's completely independent of image resolution. literally doesn't care how big your image is. main character energy. π
now, where do those four streams come from? each one is either a file or a constant. and here's the cute part: a single file can feed more than one stream β for example, the foreground file can also be the true-output file, no drama. also, the name - means stdin. periodt. π
a constant is what you get when you specify it instead of a filename, and you do that when the first character is an equal sign (=). the value is a slash-separated string of width_in_bytes decimal numbers with no separating white space. like this, bestie: =255/0/0. π
heads up: if bothin1andin2are constants, the output gets bounded to a 512 x 512 image. noted. π
the comparison formula is built from -g (greater than), -l (less than), -e (equal to), and -n (not equal to), and you can combine them β so -ge means in1 greater than or equal to in2. iconic. but important: the condition must hold for every byte of the element for the true output to be selected. every single one. no partial credit. π
π§ OPTIONS π§
-gβ select the true output wherein1is greater thanin2π₯-lβ select the true output wherein1is less thanin2π-eβ select the true output wherein1is equal toin2β-nβ select the true output wherein1is not equal toin2π-aβ approximate matching! bytes count as equal when they match within plus or minus one, which is super useful for matting dithered backgrounds. when combined with-eor-nit gives you approximately-equal or approximately-not-equal. when combined with-gand/or-lit excludes the elements that meet the approximately-equal criterion. also β and this is important, bestie β-ais a modifier only; you still gotta give at least one of-g,-l,-e, or-n. don't leave her hanging π-wwidth_in_bytes β set the width in bytes of each element. default is 3 (that's thepix(5)format); use 1 to processbw(5)files. the width must be between 1 and 31. no zero, no 32, we don't do that here π-h,-?β print a usage message and exit. the classic escape hatch π«Ά
π EXAMPLES π
Example 1. Composite a foreground over a generated background
pixbackgnd -t0 160 200 | pixmatte -n fg.pix =63/0/127 fg.pix - | pix-fb
keeps every foreground pixel that is not equal to the chroma-key color 63/0/127, and replaces matching pixels with a pixbackgnd(1) gradient read from stdin, then displays the result with pix-fb(1). this is, like, the classic way to drop an rt(1) image over a nicer background. chef's kiss. π
Example 2. Threshold against a constant
pixmatte -g fg.pix =20/20/20 fg.pix =200/0/200 > out.pix
keeps foreground pixels whose bytes are all greater than 20/20/20, and replaces the rest with the constant magenta 200/0/200. slay. β¨
Example 3. Build a black-and-white stencil matte
pixmatte -n fg.pix bg.pix =255/255/255 =0/0/0 > matte.pix
produces a stencil that's white where fg.pix and bg.pix differ and black where they match, all ready for further compositing. she's a stencil, she's a vibe. π¦
Example 4. Match a dithered background approximately
pixmatte -a -e fg.pix bg.pix =0/0/0 fg.pix > out.pix
sets to black all foreground pixels that match bg.pix to within plus or minus one per byte, preserving everything else. dithered backgrounds found quaking. ππ₯
π SEE ALSO π
brlcad(1), gencolor(1), pixbackgnd(1), pixmerge(1), pix-fb(1), pix(5), bw(5)
go read them, bestie, they're all in the group chat π
π AUTHOR π
BRL-CAD Team β the collective, the moment, the icon π
π COPYRIGHT π
This software is Copyright (c) 1989-2026 by the United States Government as represented by U.S. Army Research Laboratory. fr fr, that's the whole line. π«Ά
π BUG REPORTS π
Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org β go tell them, they want to know, do not gatekeep π
okay that's the whole page!! and before you go β this gorgeous thing comes to you from BRL-CAD (that's the source/version bit at the bottom, don't @ me), so when you're piping mattes at 2am just remember who raises you π β¨π
π¦ where this page comes from
- nixpkgs unstable: brlcad 7.44.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms