Skip to documentation
DocumentationAll documentsEnglish

PIXCOUNT(1)

NAME

pixcount - count occurrences of each unique pixel color in an image stream

On this page

SYNOPSIS

pixcount [-#_bytes_per_pixel_] [_infile.pix_ [_outfile_]]

DESCRIPTION

pixcount reads a stream of pixels (3-byte RGB by default), tallies how many times each unique color value appears, and writes the result sorted by color value. Each output line lists the individual byte values of a pixel followed by the number of times that pixel occurred in the input.

If infile.pix is given, pixcount reads from that file; otherwise it reads from standard input. If outfile is also given, the tally is written there; otherwise it is written to standard output. Reading is refused when standard input is an interactive terminal.

The tool is format-agnostic about pixel layout: setting the bytes-per-pixel lets it process bw(5) grayscale (1 byte), pix(5) RGB (3 bytes), RGBA (4 bytes), or any other fixed-width pixel data.

OPTIONS

-# bytes_per_pixel

Number of bytes that make up one pixel. Must be a positive integer. The default is 3, matching standard pix(5) RGB data. Use 1 for bw(5) grayscale or 4 for RGBA.

-h, -?

Print a usage message and exit.

EXAMPLES

Example 1. Find the most common colors in a rendered image
pixcount moss.pix | sort -k4 -n -r | head

Tallies every unique RGB color in moss.pix, then pipes the result through sort(1) to list the ten most frequently occurring colors first. This is a quick way to inspect an image’s palette or spot a dominant background color.

Example 2. Count grayscale levels in a BW image
pixcount -#1 image.bw levels.txt

Treats the input as 1-byte-per-pixel bw(5) data and writes the count of each grayscale value to levels.txt, revealing the image’s tonal distribution.

SEE ALSO

brlcad(1), pixhist(1), pixstat(1), bw(5), pix(5)

AUTHOR

BRL-CAD Team

This software is Copyright (c) 1989-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