Color images#

Images of one field in different filters combine into a color image: the classic three as red, green and blue, or any number of filters, each drawn in its own hue. This page shows both, and how to balance the colors.

The examples use the sample field in three filters, red, green and blue (FITS files with a WCS), and four tiles of it in two filters, tiles_r and tiles_b.

Three filters as red, green and blue#

pc.rgb takes three images, longest wavelength first. Images with a WCS are aligned on the sky, so they don’t need to be the same size or pointing; images without one line up pixel for pixel.

import pixel_clarity as pc

pc.rgb(red, green, blue, scale="asinh", limits="99.5")

Each of the three can be anything pc.show takes: a path, an s3:// URI or URL, an array or an HDU. names labels them in the legend.

Balancing the channels#

By default the three channels share one stretch: the same scale function and limits mode, each applied to its own data. That keeps the colors honest. link_scales=False starts each channel with a stretch of its own; the R, G and B buttons in the toolbar pick which channel the controls change, and the % button beside each sets its opacity.

For a picture rather than a measurement, Auto enhance does the balancing for you: it sets a dark, neutral sky, balances the channels on it, and saturates the colors. auto_saturation (0 to 2.5, by default 1.4) sets how strong they come out.

pc.rgb(red, green, blue, auto=True, auto_saturation=2.0)

In the viewer, Auto’s menu also has warmth and tint sliders, and Make this white: click a star or a region that should be white, and the colors are balanced on it.

Any number of filters#

A mosaic with color=True shows each filter in its own hue, spread from red (the longest wavelength) to blue (the shortest), and adds the colors up. It’s the way images from many filters are combined, and it works with two filters as well as ten. groups gives each file’s filter, one per file:

pc.mosaic(tiles_r + tiles_b, color=True, groups=["R"] * 4 + ["B"] * 4, auto=True)

Each filter keeps its own limits and stretch: pick it in the toolbar, or click one of its tiles. In the Detectors panel each filter’s hue and opacity can be changed, or the filter left out.

When groups isn’t given, each file’s filter is read from its metadata (a FITS FILTER keyword, for example) or, failing that, its file name. With one folder per filter, the folder’s name makes a good group:

from glob import glob
from pathlib import Path

files = sorted(glob("F1/*.fits")) + sorted(glob("F2/*.fits")) + sorted(glob("F3/*.fits"))
pc.mosaic(files, color=True, groups=[Path(f).parent.name for f in files])

Exporting a color image#

Export in the toolbar, on its Full-resolution image tab, writes a full-resolution PNG of the color image, rendered next to the data, of the whole image, the view, the crop or a box, with an optional colorbar, regions and text. The file is written next to the notebook and named in the line under the viewer. The PNG carries the color settings (each channel’s limits and curve) in its metadata, so the picture can be reproduced exactly. pc.save_png(..., color=True) writes the same picture from code: see Saving pictures.