r3 - 18 Oct 2007 - 10:29:27 - JasonFaulringYou are here: TWiki >  LIAS Web  >  LiasSoftware > DcrawTerrapix
Tags:
software1Add my vote for this tag create new tag
, view all tags

dcraw is a free utility for converting raw Bayer CFA encoded imagery into color RGB. It supports a range of Bayer CFA decoding algorithms; because it is newer and actively maintained, the quality of the Bayer decoding often exceeds the offerings from commercial software. Also, unlike the software we have from GSI, there are no licensing issues to worry about.

Source Code

The homepage for dcraw is http://www.cybercom.net/~dcoffin/dcraw/ Don't let the page title scare you; this software works fine under not just Linux, but Windows, Mac OS X, Solaris, and so on. Indeed, if you read down that page a ways, you'll see that exactly the author's goal.

You have two choices for getting a version of dcraw that will decode GSI TerraPix imagery:

Option 1 - Download dcraw.c from this wiki topic. It's already been patched to support the TerraPix and is "ready to go". This version of dcraw is 8.77.

Option 2 - Download dcraw.c from its homepage above, and then apply the patch located on this page. If Dave Coffin makes a new version of dcraw than what you see on this page, and you're comfortable applying text patches, this is definitely the way to go.

Building and Installing

This is what I've been using to build the source file on various platforms. All should yield a new executable dcraw (or, on Windows, dcraw.exe) when you're done.

Once you've built the software (using the recipes below, or perhaps you have your own methods), installing it is a breeze. Simply move the dcraw utility into a directory named in your PATH variable. There are no auxiliary files or trees to set up; dcraw is a standalone executable.

Mac OS X

You'll need the JPEG and LCMS libraries on your machine to build dcraw. I recommend getting and using http://www.macports.org/ on your system, it handles downloads, builds, and installs without any trouble. Other alternatives for you here include http://finkproject.org/ and even http://www.freebsd.org/ports/

Here, I'll assume you went with MacPorts. Once you've got it installed on your system, just run the following to get the LCMS and JPEG libraries built and installed, along with all of their dependencies.

sudo port install lcms jpeg

With that in place, building dcraw is simply

cc -I/opt/local/include -O4 -o dcraw dcraw.c -L/opt/local/lib -ljpeg -lcms -lm

Solaris

You'll need the JPEG and LCMS libraries on your machine to build dcraw. I recommend getting and using http://blastwave.org/ on your system, it handles downloads, builds, and installs without any trouble. Other alternatives for you here include http://openpkg.org/ and even http://www.freebsd.org/ports/

Here, I'll assume you went with Blastwave. Once you've got it installed on your system, just run the following to get the LCMS and JPEG libraries built and installed, along with all of their dependencies.

sudo pkg-get -i lcms jpeg

With that in place, building dcraw is simply

cc -I/opt/csw/include -O -o dcraw dcraw.c -L/opt/csw/lib -ljpeg -lcms -lm

If you're feeling lucky, you could replace the -O with -fast in the command above.

Windows

A version compiled to run with Cygwin can be found here: dcraw.exe: dcraw-cygwin

Gentoo Linux

Those brave enough to run Gentoo can use the following ebuild in their Portage Overlay Directory. the ebuild will automatically download the patch and apply it when building dcraw

Running It

A basic run of dcraw looks like the following. Given a TerraPix file named VNIR039.img, this will generate a NetPBM file VNIR039.ppm

dcraw VNIR039.img

When you want to quickly "preview" an image, you can generate a quarter-scale image (2k by 2k pixels) very quickly with the -h option.

dcraw -h VNIR039.img

More often, though, it's useful to place the image on dcraw's output, rather than straight to a file. Then you can generate a JPEG image with cjpeg, for example. To place the image on output, instead of a file, add the -c option.

dcraw -c VNIR039.img |cjpeg >VNIR039.jpeg

Normally, dcraw emits 8 bit output. This is easier to work with for most software, but you'll necessarily get a compressed dynamic range of colors. Use the -4 option to generate 16 bit output (note, the output is linear, no gamma correction is applied in this case).

dcraw -4 VNIR039.img

If you're generating output to be viewed "as a picture" (rather than analyzed in a scientific manner), go ahead and hack the colors of the image. You could open the image with Photoshop and selecet "Auto Levels", for example. Myself, I like using http://imagemagick.org/ as you see here, which will both edit the image's colors as well as convert its format (from NetPBM to JPEG).

dcraw -4 -c VNIR039.img |convert ppm:- -normalize VNIR039.jpeg

We have a dark current calibration file available. It makes a small difference in most files; once in a while, it makes a huge difference. Use the -K option to specify a dark current correction. The file can be downloaded here: tpix-dark.pgm

dcraw -K tpix-dark.pgm VNIR039.img

There are a variety of decoding algorithms available via dcraw.

  • -h is the quickest, generating a quarter-scale interpolation of the image (least quality, fastest processing time)
  • -q 0 performs simple bi-linear interpolation
  • -q 1 uses the "variable number of gradients" interpolating algorithm
  • -q 2 uses "patterned pixel grouping" interpolation
  • -q 3 uses the "adaptive homogeniety-directed" interpolation. (best quality, slowest processing time)

Pulling all of these options together: this will decode the TerraPix image using the best (AHD) decoding algorithm, subtract its dark current, and generate an aesthetically pleasing image.

dcraw -c -q 3 -4 -K tpix-dark.pgm VNIR039.img |convert ppm:- -normalize VNIR039.jpeg

Bear in mind, the conversion to JPEG is always lossy. If you really need accuracy, convert the data to some other lossless format instead of JPEG. PNG or TIFF are good choices here. But, bear in mind, your final file size will go up by an order of magnitude, typically. The NetPBM format is also lossless, but has no compression and generates enormous TerraPix files.

dcraw -c -q 3 -4 -K tpix-dark.pgm VNIR039.img |convert ppm:- -normalize VNIR039.png

toggleopenShow attachmentstogglecloseHide attachments
Topic attachments
I Attachment Action Size Date Who Comment
cc dcraw.c manage 239.6 K 11 Sep 2007 - 09:44 BobKrzaczek dcraw.c - version 8.77 - patched to support terrapix imagery
elsepatch tpix.patch manage 2.2 K 11 Sep 2007 - 09:46 BobKrzaczek patch file adding support for terrapix to dcraw.c
elsepgm tpix-dark.pgm manage 32648.0 K 11 Sep 2007 - 10:25 BobKrzaczek dark current calibration file for RIT's terrapix
exeexe dcraw.exe manage 181.9 K 19 Sep 2007 - 15:48 JasonFaulring dcraw-cygwin
elseebuild dcraw-8.73.ebuild manage 2.3 K 18 Oct 2007 - 10:28 JasonFaulring Gentoo dcraw-terrapix Ebuild
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback