Skip to content

fix(fits): read/write color FITS image using the correct convention - #5385

Open
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-fitschannels
Open

fix(fits): read/write color FITS image using the correct convention#5385
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-fitschannels

Conversation

@lgritz

@lgritz lgritz commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

FITS has no formal notion of color channels, just numbered axes, and OIIO's guess for a 3D color image (NAXIS1 = nchannels, interleaved) was wrong: research while investigating issue #5384 turned up no real-world FITS software using that layout. The universal convention is NAXIS3 = nchannels, one full-resolution plane per channel, the same layout astronomical software uses for spectral and Stokes cubes.

Reader and writer now both use only that convention. The old NAXIS1-interleaved guess is dropped entirely rather than kept for compatibility: nothing but OIIO itself ever produced or consumed it, and it silently misread genuine external color cubes as volumes, which was the actual bug in #5384. Such old files now read as a plain grayscale volume instead.

We feel comfortable with that choice because (a) no software but OIIO wrote the other convention, (b) no other software could have properly read or displayed the incorrect files OIIO was writing, yet nobody ever pointed out the error or complained in any way until #5384. I am interpreting that as very strong circumstantial evidence that there are none of these wrong image OIIO produced that people still need to read with the wrong conventions.

Also fix stale, meaningless channel names, and add real names where the header supports it (STOKES axis codes, or informal FILTERn/BANDn keywords). If there are multiple channels and none of these conventions are apparent, default to just calling it R, G, B. Document the convention and channel-naming rules in builtinplugins.rst.

For the rarer NAXIS=4 (volume+color) case, apply the same pattern: the channel axis is NAXIS4, the slowest-varying one, not NAXIS1. There's no known real-world convention to confirm this against like there was for NAXIS=3, but it's the natural extension of the same reasoning.

Fixes #5384

Assisted-by: Claude Code / Sonnet 5

FITS has no formal notion of color channels, just numbered axes, and
OIIO's guess for a 3D color image (NAXIS1 = nchannels, interleaved)
was wrong: research while investigating issue AcademySoftwareFoundation#5384 turned up no
real-world FITS software using that layout. The universal convention
is NAXIS3 = nchannels, one full-resolution plane per channel, the same
layout astronomical software uses for spectral and Stokes cubes.

Reader and writer now both use only that convention. The old
NAXIS1-interleaved guess is dropped entirely rather than kept for
compatibility: nothing but OIIO itself ever produced or consumed it,
and it silently misread genuine external color cubes as volumes,
which was the actual bug in AcademySoftwareFoundation#5384. Such old files now read as a plain
grayscale volume instead.

We feel comfortable with that choice because (a) no software but OIIO
wrote the other convention, (b) no other software could have properly
read or displayed the incorrect files OIIO was writing, yet nobody
ever pointed out the error or complained in any way until AcademySoftwareFoundation#5384. I am
interpreting that as very strong circumstantial evidence that there
are none of these wrong image OIIO produced that people still need to
read with the wrong conventions.

Also fix stale, meaningless channel names, and add real names where
the header supports it (STOKES axis codes, or informal FILTERn/BANDn
keywords). If there are multiple channels and none of these
conventions are apparent, default to just calling it R, G, B. Document
the convention and channel-naming rules in builtinplugins.rst.

For the rarer NAXIS=4 (volume+color) case, apply the same pattern:
the channel axis is NAXIS4, the slowest-varying one, not NAXIS1.
There's no known real-world convention to confirm this against like
there was for NAXIS=3, but it's the natural extension of the same
reasoning.

Fixes AcademySoftwareFoundation#5384

Assisted-by: Claude Code / Sonnet 5

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Wrong channel count when reading FITS image

1 participant