LinuxCommandLibrary

fitstopnm

Convert FITS image to PNM image format

TLDR

Convert a FITS file to a PNM image

$ fitstopnm [path/to/file.fits] > [path/to/output.pnm]
copy

Convert the image on the specified position of the third axis in the FITS file
$ fitstopnm [[-i|-image]] [z_position] [path/to/file.fits] > [path/to/output.pnm]
copy

SYNOPSIS

fitstopnm [-verbose] [-image n] [-maxspan] [fitsfile]

PARAMETERS

-verbose
    Prints progress, statistics, and file info to stderr.

-image n
    Selects the nth image (HDU) in the file; n starts at 1 (default: 1).

-maxspan
    Scales via mean ±3σ for high dynamic range; forces 16-bit output.

DESCRIPTION

fitstopnm is a utility from the Netpbm graphics toolkit that reads FITS (Flexible Image Transport System) files—a standard format for astronomical data and images—and converts them to PNM (Portable Anymap) output. The output is PBM for bitmaps, PGM for grayscale, or PPM for color pixmaps, based on the FITS image properties.

FITS files often contain multiple images in Header Data Units (HDUs). fitstopnm defaults to the first image but allows selection of others. It handles various pixel data types including 8-bit, 16-bit integers, and 32-bit floats, scaling them appropriately.

By default, pixel values are linearly scaled from the image's minimum (to 0) and maximum (to 255 or 65535). The -maxspan option uses statistical scaling: mean minus 3 standard deviations maps to 0, plus 3 standard deviations to 65535, producing 16-bit output. This is ideal for scientific images with vast dynamic range, like star fields dominated by dark sky.

Input comes from stdin or a file; output goes to stdout. It's designed for pipelines with other Netpbm tools.

CAVEATS

Limited support for complex FITS features like tables, spectra, or non-image HDUs; may fail on malformed or extended-variant files. No color support in grayscale FITS. Assumes IEEE float format.

EXAMPLES

fitstopnm galaxy.fits | pnmtopng > galaxy.png
fitstopnm -maxspan -image 2 -verbose deepfield.fits > deepfield.pgm

OUTPUT NOTES

Max sample depth: 8-bit (default scaling) or 16-bit (-maxspan). Monochrome FITS yields PGM; rare color yields PPM.

HISTORY

Part of Netpbm suite since version 9.25 (circa 2002), with FITS support implemented by Bryan Henderson. Evolved with Netpbm releases for better astronomy image handling.

SEE ALSO

pnmtofits(1), pgm(5), ppm(5), pnmtopng(1)

Copied to clipboard