Fitspng is an utility intended to convert of images in astronomical FITS to PNG format.
FITS format is a general purpose astronomical image format. FITS images stores measurements of a physical quantity — an array of the angular distribution of the photon events or the optical intensity. Fitspng does visualisation of such array by converting them to the images in PNG format.
Fitspng applies a global tone mapping technique to transform of a wide dynamical range of FITS files (naturally including HDR) to the limited range of, so called, modern displaying devices and image formats.
The tone mapping includes these steps: a linear pre-scaling and optional application of an intensity transfer function.
Pre-scaling maps linearly the captured counts, related to optical intensities I (I ∋ ℝ, I ≥ 0 ), to the range 0 ≤ t ≤ 1 by the two parameter transformation:
t = (I - B) / s.
As the parameters, B – black level, and s – sensitivity, has been selected.
B sets a background level in original data. It corresponds to zero in transformed values, and finally to the black colour.
The sensitivity s > 0 adjusts a range of FITS values visible on PNG pictures. It simulates the artificial sensitivity of a detector: adjusting of sensitivity s leads to a dim, or highlight, images — it operates like a gain of an electronic amplifier of a detector. This parameter is a reciprocal quantity to ISO value used by photographers.
The linear transformation should be followed by a cut-off, which assigns all values below the level B to be black, and over the interval to be white:
t = { (I - B) / s ∈ (0, 1) }
Itt scaling applies a intensity transfer function f(t) (the intensity transfer table ITT in the past) on the pre-scaled data t:
τ = f0 · f(t) + z0,
f0, z0 are Itt function scaling parameters (f0=1, z0=0 by default). If f(t) is the linear function, the function becomes identity τ = t, and f0, z0 remains no applied.
Various Itt functions (linear, logistics .. ) are described in paragraph Itt functions.
Gamma correction Finally, the light-sensitivity model, specific to a displaying device, sRGB or AdobeRGB (pdf) is applied onto τ values by Gamma function Γ(τ):
p = { 255 Γ(τ) ∈ (0, 255) },
where p is the final value stored in PNG.
The described pre-scaling is applied on all pixels in the frame; one is applied on values for grey-scale, and on every channel of colour images.
Both B, s parameters can be leaved unspecified: they are estimated by the included machine algorithm described in Tone parameters estimation. A manual setup of the pre-scale parameters is available in two modes:
A reliable setup of the scaling parameters B, s is crucial for proper function of Fitspng; a novel approach on base of quantiles of an empirical distribution function has been developed.
Background level is estimated as 25% quantile QB of empirical CDF of observed pixels. It is close to CDF of Normal distribution for the sky, a star free background. The black level is adjusted by the quantile:
B = QB(¼)
The pixels included in determination of the CDF are pre-selected from a grid over the full frame (over 30 thousands of data points). The one-quarter value is a result of empirical experiments.
Light upper level is estimated as 95% quantile of the empirical CDF constructed on base of pixels with values above ≥ 3 D of the background CDF. The pixels contains only a star light, or another star-gazing objects, and provides the range for observed intensity values.
s0 = QL(95%)
Parameter D is a quantile estimation of dispersion on base of ¼ and ¾ of QB quantiles (QN(½) ≐ 0.6745 is 50% quantile of Normal distribution):
D = [QB(¾) - QB(¼)] / [2 · QN(½)]
Relative parameters q, v are defined by the way:
The relative parameter q ∈ (0,1) is a quantile of QB(q).
Common properties of QB(q) are: q = ½ is arithmetic mean, q = ¼ (standard background level) is the mean of absolute deviations under the mean, q=0 or q=1 are minimal and maximal values.
The parameter 0.001 < v < 1000 (mostly) adjusts relative slope against to the pre-defined value s0.
The empirical CDF for an ordinary picture of sky is displayed on the graph below. The vertical axis shows quantiles, the horizontal axis of picture values. The background noise follows Normal distribution up to Q = 0.8; the star light is getting importance over the background since the level.
The empirical CDF of an ordinary picture of sky, see text for description.
The histogram of the same frame.
Fitspng implements the functions:
The choice of analytical form of the functions asymptotically reproduces the linear function close to zero.
The square root function reveals the relative error of observed values: the error is proportional to √t / t (reciprocity to the Itt above) by Poisson distribution. The bright parts of life has smaller relative errors over the dark parts.
The logistics function emulates the gradation curve of the classical photographic emulsion.
Colour FITS frames, defined by Munipack, are recognised. The colours can be tuned.
Saturation The colour saturation of images should be reduced when the relative saturation parameter has value c < 1, or enhanced when c > 1. The saturation of the final frame is computed by formula
c √C,
with the chroma C = a2 + b2 specifying of the saturation in L*a*b colour-space.
Nite vision The human eye sensitivity in high and low light conditions can be artificially simulated by greying of dim parts of images by application of Purkyně effect.
The photopic (colour) and scotopic vision is modelled by the mix weighting function
w = ½ {1 + erf [(t - tn) / sn]},
with the night vision threshold tn, and a half-with of sn of the mesotopic vision region. Be warned, the function has been selected by heuristic: there is no a proof of validity.
The values are mixed with X, Y, Z channels giving ranges 0 ≤ tn ≤ 100 and sn > 0. Pictures becomes fully coloured for tn → 0, or complete in night vision for tn → 100. The mesotopic regime has tn around 50.
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.
FITS header meta-information is stored as an EXIF information of PNG files: the EXIF text strings has free format and no formalised custom.
fitspng [options] file(s)
Specify an output file name, single file only.
If this switch is omitted, the output filename is determined by modification of the input filename(s): suffixes, like *.fits, are replaced by *.png, and the directory path is removed: /space/image.fits is converted to image.png. The approach leaves original data untouched, results are stored in the current working directory (see also Examples).
Convert a FITS image to PNG:
$ fitspng -o grey.png grey.fits
Emulate the human night vision:
$ fitspng -o scotopic.png colour.fits
Emulate the classical photography sensitivity function (gradation curve):
$ fitspng -f logistic -o photo.png colour.fits
Create a semi-grey image:
$ fitspng -fs 0.2 -o reduced.png colour.fits
Generate thumbnails of FITS files in /space; files are stored under the current directory
fitspng -s 10 /space/*.fits
The same result should be emulated with help of shell scripting (providing powerful file name manipulations):
$ for FITS in /space/*.fits; do NAME=$(basename $FITS); PNG=${NAME%fits}png; fitspng -s 10 -o $PNG $FITS; done
Fitspng has no parallel run support build-in due portability issues; however, the execution time on multiprocessor systems should be significantly reduced with help of an external utility:
$ ls /space/*.fits | xargs -n 1 -P 2 fitspng
#1, Colour image in sRGB
#2, Colour image in AdobeRGB
#3, Highlighted
#4, Shadowed
#5, Reduced colours
#6, Enhanced colours
#7, Photography tone
#8, Night vision
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 -s 10 -o IMG_5952.png IMG_5952.fits #1 $ fitspng -cs AdobeRGB -s 10 -o IMG_5952_a.png IMG_5952.fits #2 $ fitspng -fr 3,10 -s 10 -o IMG_5952_fr10.png IMG_5952.fits #3 $ fitspng -fr 3,50 -s 10 -o IMG_5952_fr50.png IMG_5952.fits #4 $ fitspng -fs 0.5 -s 10 -o IMG_5952_s05.png IMG_5952.fits #5 $ fitspng -fs 1.5 -s 10 -o IMG_5952_s15.png IMG_5952.fits #6 $ fitspng -f logistic -s 10 -o IMG_5952_ph.png IMG_5952.fits #7 $ fitspng -fn 3000,100 -s 10 -o IMG_5952_fn.png IMG_5952.fits #8
The tar-ball, or the development repository, is freely available under GPL-3 licence. Both cfitsio and libpng libraries, including files required for development (headers, static libraries), are 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 should 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.
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 — 2019, F. Hroch, Institute of Theoretical Physics and Astrophysics, Masaryk University, Brno, Czech Republic.