Fitspng is an utility intended to convert of images in astronomical FITS to PNG format.
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.
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:
black = median - u*mad
sensitivity = 1/(v*mad)
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.
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.
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.
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.
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.
fitspng.png
.
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
Color image in sRGB
Color image in AdobeRGB
Highlighted
Shadowed
Reduced colors
Enhanced colors
Photography tone
Night vision
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
Munipack is a general utility to work with FITS images.
Development notes can be found in Hroch's diary.
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.