Fitspng

Fitspng is an utility intended to convert of images in astronomical FITS to PNG format.

Introduction

FITS format is a general purpose astronomical format storing images in high dynamical range (naturally including HDR). The primary goal of fitspng is to transform of the high dynamic range images to a limited numerical range of PNG format. The transformation uses global tone mapping technique by a set of tone functions. Their scaling parameters can by estimated by a machine or provided by user.

Tone mapping

Fitspng uses global tone mapping technique to convert of a wide dynamical range (which can be practically infinite) to limited range of modern displaying devices. The usage of the tone mapping is crucial to get a visually satisfactory picture results.

The tone mapping is generally described by following transformation:

PNG value = f0 * Func[ (FITS value - black) * sensitivity ] + zero

where Func is a selected function (linear, asinh, ..) and f0, zero are profile scaling parameters (f0 is defaulted to 1 and zero to 0). FITS values are pre-scaled by parameters black and sensitivity to an appropriate domain of Func. The black sets a level of FITS values corresponding to the black on output. The sensitivity parameter sets an artificial (fake) sensitivity of detector. The sensitivity dims or highlights of the image like a gain tuning of an electric amplifier in detector. The sensitivity is a reciprocal to ISO value used by photographers.

Both parameters black and sensitivity can be leave unspecified. In this case, ones are estimated by the included machine algorithm with help of statistical parameters: median and mean of absolute deviations (mad). Both parameters are describing of a histogram of data: median marks centre of histogram and mad scales width of histogram.

There are available two modes:

Both median and mad parameters are determined using of a ten node pixel grid over the image. Mad is mean of positive deviations from median. The default is u = 0.5, v = 15.

If any pixel is out of range 0 to 255 as result of mapping, the value is replaced by 0 or 255 respectively.

Colour processing

If colour FITS (as defined by Munipack) is converted, one can manipulate with colours by specifying of saturation in *L*u*v colour-space.

Moreover, the human eye has different colour sensitivity in high and low light conditions. The effect can be simulated by greying of dim parts of images application of PurkynÄ› effect.

Output colour spaces

Fitspng transforms images to sRGB or AdobeRGB colour-space. The transformation is started from FITS provided CIE 1931 XYZ colour-space to CIE *L*u*v. The luminosity channel is scaled according of parameters and tone functions and finally transformed to sRGB or AdobeRGB (pdf). Note that both RGB conversions uses gamma function to scale output intensities of RGBs.

In the case of grey scale image, values are equivalent to *L component whilst *u,*v are identically zero. Therefore just a tone mapping and the gamma correction is applied to output images.

Image resize

An output image can be scaled-down by an integer factor. Every pixel of the scaled image is computed as the arithmetical mean of a square with side given by this factor. The photometric information is preserved while a noise is suppressed during the re-scaling. This sufficient fast method provides high quality images.

Exif information

Any exposure parameters of images are stored in FITS header which is practically analogy of an EXIF information stored as a text strings in PNG so basic header information from FITS files is extracted during the conversion.

Command line options

-f [linear|asinh|log|gamma|normal|sqrt|sqr|logistic|atan]
Global tone mapping function profile: linear, asinh, log, gamma (as in sRGB), normal (Gauss cumulative distribution function), square root, square, logistic (emulating classical photography sensitivity) and atan.
-f0 f0
Scale of output profile: f0*Func(...) + z.
-fz z
Zero of output profile: f0*Func(...) + z.
-fr u,v
Relative scaling mode. u,v multipliers for median and mad.
-fl t,s
Absolute scaling mode. t,s are directly used for determining of mapping parameters. The setup completely disables internal parameter estimation.
-fs x
The colour saturation is multiplied by the given factor (for colour FITS only).
-fw x,y
Coordinates of the white point.
-fn st,ss
When used, switch-on mode which emulates humans night vision. It is useful only for colour FITS.
-cs [sRGB|AdobeRGB]
Select the colour-space of output image.
-s s
Scale the size of image down by the specified factor s as a (non-zero) positive integer number. If the s factor is greater of one, any output pixel is constructed as the arithmetical mean of s*s input pixels.
-o name
Output image name. Default value is fitspng.png.
-B [8|16]
8 bites per pixel of colour (grey) depth of output. This is default. 16 bites per pixel of colour (grey) depth of output. There is frequently problem with additional rendering. Most of utilities doesn't work with this colour depth correctly. On the other side, 16 bit per pixel images has saved photometric content more precisely.
-v
Print additional information during processing.
-h, --help, --version
Show summary of options or the current version.

Examples of usage

Convert a FITS image to PNG:

$ fitspng grey.fits -o grey.png

Emulate humans night vision:

$ fitspng colour.fits -o colour.png -fn 100,10

Emulate the classical photography sensitivity function (density curve):

$ fitspng colour.fits -o colour.png -f logistic

Create a semi-grey image:

$ fitspng colour.fits -o colour.png -fs 0.2

Select just only Y band of a colour FITS (using FITS file name extension):

$ fitspng "colour.fits[*,*,2]" -o green.png

Generate thumbnails (with help of shell scripting):

$ for A in *.fits; do fitspng -s 10 $A -o ${A%fits}png; done

Gallery

All this gallery examples has been generated by processing of the reference raw photo IMG_5952.CR2 :

$ rawtran -o IMG_5952.fits IMG_5952.CR2
$ fitspng IMG_5952.fits -o IMG_5952.png -s 10
$ fitspng IMG_5952.fits -o IMG_5952_a.png -s 10 -cs AdobeRGB
$ fitspng IMG_5952.fits -o IMG_5952_fn.png -s 10 -fn 3000,100
$ fitspng IMG_5952.fits -o IMG_5952_ph.png -s 10 -f logistic
$ fitspng IMG_5952.fits -o IMG_5952_s05.png -s 10 -fs 0.5
$ fitspng IMG_5952.fits -o IMG_5952_s15.png -s 10 -fs 1.5
$ fitspng IMG_5952.fits -o IMG_5952_fr10.png -s 10 -fr 3,10
$ fitspng IMG_5952.fits -o IMG_5952_fr50.png -s 10 -fr 3,50
IMG_5952

Colour image in sRGB

IMG_5952

Colour image in AdobeRGB

IMG_5952

Highlighted

IMG_5952

Shadowed

IMG_5952

Reduced colours

IMG_5952

Enhanced colours

IMG_5952

Photography tone

IMG_5952

Night vision

Download and installation

The tar-ball or the development repository with a source code is freely available under GPL-3 licence. Both cfitsio and libpng libraries with files required for development (headers, static libraries) is necessary for building.

A recommended way of installation under Unix-like system is:

$ tar zxf fitspng-X.Y.Z.tar.gz
$ cd fitspng-X.Y.Z/
$ autoreconf -i   # for Mercurial
$ ./configure CFLAGS="-O4 -DNEBUG"
$ make
# make install

The last step must be executed under root account. Both binary and man page are installed under /usr/local tree. It would be nice to keep the directory for case of later uninstalling.

See also

Munipack is a general utility to work with FITS images.

Development notes can be found in Hroch's diary.

License

Fitspng is free software licensed under the GNU General Public License. This gives you the freedom to use and modify Fitspng to suit your needs.

Copyright © 2006 - 2017, F. Hroch, Institute of Theoretical Physics and Astrophysics, Masaryk University, Brno, Czech Republic.