Rawtran

Rawtran is an utility to convert of raw photos in CR2, CRW, MRW, etc. formats to the astronomical FITS image format.

Introduction

Modern digital cameras offers possibility to save raw photos, eg. only slightly preprocessed photos intended for further image processing. Rawtran is developed as a wrapper around dcraw by D.Coffin to produce FITS files widely used by astronomers. Output FITS files could be used for aditional processing by any standard astronomical software (like an image acquired by a scientific CCD camera). It means the images are suitable for all photometrical, spectroscopical or astrometrical measurements.

Every digital camera has own representation of colors reflecting individual instrument characteristics. By another words, the spectral sensitivity of color pixels varies from a camera to a camera. To get a correct color representation, we need transform raw color data to some standard color space. The transformation is provided by dcraw, which includes color transformation matrices for wide range of digital cameras. Dcraw facility can produce output data in the exactly defined CIE 1931 XYZ color space. Unfortunately, the XYZ components are pre-scaled so the absolute photometric information is lost. That means that the XYZ components (and derived quantities) should be supposed as relative measurements only.

Rawtran offers following kinds of FITS files:

Type: color (-t 0)

The output image is the color FITS image. Because, there is no widely accepted convention or definition of color representation in FITS world, RAWTRAN uses Munipack's specification of color FITS:

The purpose of the type is a simple manipulation (and representation) of color images in FITS format. The color FITS are intended to be displayed by xmunipack (GUI for Munipack) or converted to PNG by fitspng (All included images on this page has been generated with help of the utility).

Type: instrumental (-t 1)

The output image contains one 3D primary array without any photometric transformations. Four bands are stored in an array with the structure: width ⨉ height ⨉ 4. The bands are in order: R (red), G1 (green1), G2 (green2), B (blue). According to astronomical terminology, the single bands are in an instrumental photometric system.

The type provides absolutely raw access to data in FITS format. One offers a direct conversion between file formats (it rearranges bytes only) and does NOT modify data itself. To be useful, transform the data to any known color space by using of a transformation matrix (included in the source code of dcraw.c).

Type: single spectral band (-t . -c .)

The type is intended for representation of the intensity in the selected color band. The output image is a greyscale and data are stored as two dimensional FITS primary arrays.

In case of instrumental intensities, a single instrumental band will be selected with help of -c switch. Colors Ri,Gi1,Gi2,Bi are simply copied out from the the appropriate Bayer's mask. Gi is derived as arithmetical mean Gi = (Gi1 + Gi2)/2. These instrumental RGB filters are specific for an unique camera model.

With exact definition of XYZ spectral profiles, we can derive of color transformation matrix to another colorspace. Probably most useful is the astronomical photometry BVR system. Rawtran has built-in the transformation matrix from XYZ to Landolt's BVR photometry system. A required photometry band can be selected with -c switch.

In case of standard band intensities, the XYZ components are stored or another spectral bands are derived. Note, that Y component represents luminance. Its spectral profile is similar to humans eye spectral sensitivity under well-light conditions (photopic vision). Other components in XYZ color space can be selected by specifying of -c switch.

It is also possible to specify of a wide-spectral band (like the human eye or an unfiltered CCD image) or to simulate scotopic vision (like human eye under low-light conditions). The visual difference between color images (or Y component) and the scotopic one illustrates Purkyňův effect.

Note, that all data are slightly modified as result of a color interpolation on Bayer's mask. Use -X "-h" to switch-off the interpolation.

All data must be supposed as RELATIVE quantities only.

Command line options

-t [0|1]
Specify a type of conversion:
0
Standard spectral band(s) (default)
1
Instrumental spectral band(s) (direct copy of Bayer's mask color).
-c [X|Y|Z|R|V|B|u|s] or [Ri|Gi|Gi1|Gi2|Bi]
Selects a color band:
X,Y or Z
CIE XYZ 1931 colorspace. Y is the human eye sensitivity under well-light conditions.
B,V or R
Landolt's astronomical photometry system
u
Unfiltered, integrated over full camera spectral sensitivity, u = X + Y + Z for all pixels.
s
Scotopic. The human eye sensitivity under low-light conditions, s = 0.36169 Z + 1.18214 Y - 0.80498 X for all pixels.
Ri,Gi,Gi1,Gi2 or Bi
Instrumental, camera specific color in Bayer's mask. Added a mean green as Gi=(Gi1+Gi2)/2 for all pixels.
Filters X,Y,Z,R,V,B,u,s can be used just only for standard type conversion (-t 0) and filters Ri,Gi[1,2],Bi for instrumental (-t 1). A wrong specification is silently ignored.
-b [8|16|32|-32]
Select bits per pixel of an output image. Possible values are: 8 (0-255), 16 (0-65535), 32 (0-4294967296) and -32 (-10^38 .. 10^38), (values in braces indicates numerical range). An optimal bitpix for raw (instrumental) data is 16 (default) which covers a full range of digital cameras. Some out of range (rare) values will be suppressed (cut-off). The representation occupies width*height*2 bytes. The representing by float numbers (eg. -32) is recommended value for images intended for further processing because saves numerical precision and their numerical range (but occupies of twice more space with respect to 16). 8 bits reduces range (eg. suppress dynamical range) and 32 wastes a lot of storage place only.
-o file
Output file name. If the option is not used, the output is stored as rawtran.fits. Use dash '-' for redirection to the standard output. Precede the filename with exclamation point(!) to overwrite existing file.
-X options
Specify additional options to dcraw itself. If you need pass more options, enclose ones to quotes or apostrophes. In doubts, use -X "-v" to show the detailed trace of the conversion provided by dcraw.
-h, --help, --version
Show summary of options or current versions.

Rawtran internally represents data as 4-byte (float) data during all numerical operations.

Return value

The zero indicates successful conversion. A non-zero value is returned when an error occurs during conversion. If the utility is launched without options or with -h switch, zero means that rawtran's internal checker can run dcraw binary and non-zero value otherwise.

Examples of usage

Convert an image to grayscale as an equivalent to humans eye brightness sensitivity at day:

bash$ rawtran -o IMG_0666.fits IMG_0666.CR2

Convert an image to be equivalent to Landolt's B filter:

bash$ rawtran -c B -o IMG_0666.fits IMG_0666.CR2 

Produce a color FITS and show it in xmunipack:

bash$ rawtran -o IMG_0666.fits IMG_0666.CR2 
bash$ xmunipack IMG_0666.fits

Get (mean) green component of the raw photo:

bash$ rawtran -t 1 -c Gi -o IMG_0666.fits IMG_0666.CR2 

Overwrite an output file:

bash$ rawtran -o '!IMG_0666.fits' IMG_0666.CR2 

A large set of raw photos can be converted with help of shell:

bash$ for A in *.CR2; do rawtran -o ${A%CR2}fits ${A}; done

Included examples has been generated as:

rawtran IMG_5952.CR2 -o IMG_5952.fits
rawtran IMG_5952.CR2 -o IMG_5952_X.fits -c X
rawtran IMG_5952.CR2 -o IMG_5952_Y.fits -c Y
rawtran IMG_5952.CR2 -o IMG_5952_Z.fits -c Z
rawtran IMG_5952.CR2 -o IMG_5952_B.fits -c B
rawtran IMG_5952.CR2 -o IMG_5952_V.fits -c V
rawtran IMG_5952.CR2 -o IMG_5952_R.fits -c R
rawtran IMG_5952.CR2 -o IMG_5952_Bi.fits -c Bi -t 1
rawtran IMG_5952.CR2 -o IMG_5952_Gi.fits -c Vi -t 1
rawtran IMG_5952.CR2 -o IMG_5952_Ri.fits -c Ri -t 1
rawtran IMG_5952.CR2 -o IMG_5952_s.fits -c s
rawtran IMG_5952.CR2 -o IMG_5952_u.fits -c u

fitspng IMG_5952.fits -fl 0,20000 -s 10 -o IMG_5952.png
fitspng IMG_5952_X.fits -fl 0,20000 -s 10 -o IMG_5952_X.png
fitspng IMG_5952_Y.fits -fl 0,20000 -s 10 -o IMG_5952_Y.png
fitspng IMG_5952_Z.fits -fl 0,20000 -s 10 -o IMG_5952_Z.png
fitspng IMG_5952_R.fits -fl 0,20000 -s 10 -o IMG_5952_R.png
fitspng IMG_5952_V.fits -fl 0,20000 -s 10 -o IMG_5952_V.png
fitspng IMG_5952_B.fits -fl 0,20000 -s 10 -o IMG_5952_B.png
fitspng IMG_5952_s.fits -fl 0,20000 -s 10 -o IMG_5952_s.png
fitspng IMG_5952_u.fits  -fl 0,40000 -s 10 -o IMG_5952_u.png
fitspng IMG_5952_Ri.fits -fl 128,1000 -s 10 -o IMG_5952_Ri.png
fitspng IMG_5952_Gi.fits -fl 128,1000 -s 10 -o IMG_5952_Gi.png
fitspng IMG_5952_Bi.fits -fl 128,1000 -s 10 -o IMG_5952_Bi.png
IMG_5952

Color FITS

IMG_5952_X

X component

IMG_5952_Y

Y component

IMG_5952_Z

Z component

IMG_5952_R

R filter

IMG_5952_V

V filter

IMG_5952_B

B filter

IMG_5952_Ri

R Bayer instrumental

IMG_5952_Gi

G Bayer instrumental

IMG_5952_Bi

B Bayer instrumental

IMG_5952_u

Unfiltered

IMG_5952_s

Night vision

Reference image

Download and Installation

Source code is freely available under GPL2 license. cfitsio library with developing support files (headers, static libraries) is necessary for successful building.

A recommended way of installation is:

$ tar zxf rawtran-X.Y.Z.tar.gz
$ cd rawtran-X.Y.Z/
$ ./configure
$ 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.

Dcraw must be available for proper function of Rawtran.

Rawtran runs under any Unix-like operating system (all flavours of GNU/Linux and BSD, Solaris, Mac OS X, etc). Usage under Windows or DOS has not been reported yet.

Rawtran 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 rawtran-X.Y.Z.tar.gz
$ cd rawtran/
$ dpkg-buildpackage
# dpkg -i ../rawtran_X.Y.Z-1_arch.deb

Details

Rawtran is a wrapper around dcraw. One internally launches following commands and process their output. The command to get info about image (EXIF information) is:

dcraw -i -v -c

The image data are gathered with help of commands:

dcraw -4 -c -o 5    (type 0)
dcraw -4 -c -D      (type 1)

See Also

Fitspng is a converter from FITS to PNG. Munipack is a general utility to work with FITS images.

Development notes can be found in Hroch's diary.

License

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

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