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 offering 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 by a set of tone functions with machine estimated or user provided scaling parameters.

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 prescaled 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 center 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.

Color Processing

If color FITS (as defined by Munipack) is converted, one can manipulate with colors by specifying of saturation in *L*u*v colorspace.

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

Output Color Spaces

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

In the case of gray 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 rescaling. 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 color saturation is multiplied by the given factor (for color FITS only).
-fw x,y
Coordinates of white point.
-fn st,ss
When used, switch-on mode which emulates humans night vision. It is useful only for color FITS.
-cs [sRGB|AdobeRGB]
Select the colorspace 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 color (gray) depth of output. This is default. 16 bites per pixel of color (gray) depth of output. There is frequently problem with additional rendering. Most of utilities doesn't work with this color depth correctly. On the other side, 16 bit per pixel images has saved photometric content more precisely.
-v
Print additional informations during processing.
--help, --version
Show summary of options or current versions.

Examples of usage

Convert a FITS image to PNG:

bash$ fitspng gray.fits -o gray.png

Emulate humans night vision:

bash$ fitspng color.fits -o color.png -fn 100,10

Emulate the classical photography sensitivity function (density curve):

bash$ fitspng color.fits -o color.png -f logistic

Create a semi-gray image:

bash$ fitspng color.fits -o color.png -fs 0.2

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

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

Generate thumbnails (with help of shell scripting):

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

Included examples has been generated by:

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

Color image in sRGB

IMG_5952

Color image in AdobeRGB

IMG_5952

Highlighted

IMG_5952

Shadowed

IMG_5952

Reduced colors

IMG_5952

Enhanced colors

IMG_5952

Photography tone

IMG_5952

Night vision

Reference image

Download and Installation

Source code is freely available under GPL-3 licence. cfitsio and libpng libraries with developing support files (headers, static libraries) are necessary for successful building.

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

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

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 uninstallation.

Fitspng can be build also under any DEB-based GNU/Linux distribution (like Ubuntu, Mint or Debian). Install build-essential package and build it as:

$ tar zxf fitspng-X.Y.Z.tar.gz
$ cd fitspng-X.Y.Z/
$ export DEB_CFLAGS_SET="-O4 -DNEBUG"
$ dpkg-buildpackage
# dpkg -i ../fitspng_X.Y.Z-D_arch.deb

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 - 2016, F. Hroch, Institute of Theoretical Physics and Astrophysics, Masaryk University, Brno, Czech Republic.