Working with raw images on Linux
This article is part of the LWN Grumpy Editor series. |
Most digital cameras are set to produce JPEG files; for many applications, such files are more than good enough. But most decent cameras support other formats, and a vendor-specific raw format in particular. The raw format contains something close to what was measured by the sensor, with a minimum of processing in the camera. These files are large, unwieldy, and in a proprietary format, which argues against their use in many situations. But, by virtue of holding the original image data, raw files give the photographer a much wider range of options later on. Much of the processing normally done in the camera (white balance, histogram adjustment, etc.) can be tweaked later on. For this reason, people who do photography for a living often prefer to record in the raw format.
Even for the rest of us, who have no hope of earning a living that way, raw files can keep creative options open. For people who like to play with HDR techniques there is an additional advantage: the camera typically record 12 to 16 bits of data for each channel - rather more than fits into a JPEG file. That, in turn, means that the dynamic range of raw files is significantly higher - assuming, of course, that the camera has a sensor which can meaningfully record data at that resolution. The extra range can be used to increase detail in images in a number of ways, including the use of tone mapping techniques.
Raw file formats are created by camera manufacturers, who generally feel no need to document their work. They will usually sell you a tool for decrypting their raw files - but, strangely enough, Linux support is usually missing from the feature list. Fortunately, the free software world benefits from the work of Dave Coffin, who has set a task for himself:
The result is dcraw, which comes awfully close to meeting that goal. It supports a huge list of cameras, and it does so at a high level of quality - arguably better than the vendor's tools. It is a command-line tool, aimed at batch operation or invocation from other programs; dcraw can be run from a gimp plugin, for example. Just about anything one wants to do with a raw image file is supported by dcraw.
The only downside is that processing raw images can be an interactive
process. If one wants to make adjustments, a command-line tool can get
tiresome after a while. The answer to that complaint is the UFRaw tool, which is built on
dcraw. UFRaw allows adjustment of the white and black points, gamma curve,
white balance and more - all with immediate visual feedback. When the
desired result is achieved, it can be saved in a number of formats.
UFRaw is not perfect. It's one of those applications that thinks it's clever to remember where the last image was stored and put the next one in the same directory. Your editor, instead, expects programs to default to the directory they were started in, or, failing that, to the directory where the source file was found. It's aggravating to save a file then have to figure out where the application decided to put it. UFRaw is doubly obnoxious in this regard because it immediately exits after saving the file. The non-resizeable window is also annoying. One assumes these little difficulties can be dealt with eventually; meanwhile, the core functionality is good stuff.
What sort of results can one expect? Here are three versions of the window view photo featured in the HDR article:
Original | UFRaw edited | Tone mapped |
---|---|---|
![]() |
![]() |
![]() |
(See this page for larger versions of the pictures).
Some quick editing with UFRaw was sufficient to bring out a fair amount of detail in the plant in the foreground - though the background lost some contrast as a result. The tone-mapped photo does better at maintaining contrast throughout the frame. The end result is not as complete as the full HDR image (visible here), but it does show that raw files contain information which can be recovered later on to improve the picture. Taking a single raw image is much easier than the full bracketed HDR technique, and it allows tone mapping techniques to be used on subjects which stubbornly refuse to stand still for a few minutes while several shots are taken.
One thing worth noting in conclusion: we should not take our ability to work with raw images for granted. Vendors like Nikon and Sony are known for encrypting their raw formats. The language they use to justify themselves will look most familiar; consider this advisory from Nikon regarding its NEF format:
In other words, photographers are being locked out of their own images for their own benefit. All of the usual counterarguments apply here; photographers might just have their own idea of where there benefit lies. And what happens to those raw images a decade or two from now, when the vendor has long since ceased to support the format and, even if one can find one's single legal backup copy of the software, it refuses to run on currently available systems? Fortunately, we have dcraw, which will document the reading of these formats indefinitely.
So far, vendors' attempts to encrypt raw files have been broken in short order. Chances are that trend will continue. But there is little difference between breaking into a raw image file and turning off the copy protection bits inside a PDF file. The stage is clearly set for an ugly battle, probably involving the DMCA, when some vendor decides to turn nasty.
Photographers have been worried about this issue for a few years now;
efforts like the OpenRAW project have
been working, with little success, to get camera manufacturers to open up
their formats. Adobe has been pushing its Digital Negative format as a
standard; it would be a step in the right direction, but this format still
has mechanisms for the embedding of vendor "private" information. At this
time, there does not seem to be a clear solution in sight. We must deal
with cameras just like we deal with many other types of hardware: we have
to figure out how it works ourselves.
Posted Mar 29, 2007 1:22 UTC (Thu)
by felixfix (subscriber, #242)
[Link]
Posted Mar 29, 2007 9:51 UTC (Thu)
by nix (subscriber, #2304)
[Link] (5 responses)
Posted Mar 29, 2007 20:25 UTC (Thu)
by leoc (guest, #39773)
[Link] (3 responses)
It seems to me that the lack of interest that the general public has shown about the increasing problems around intellectual property has emboldened corporations to push even further into claiming ownership of things that people have usually taken for granted. Sooner or later people will wake up to this, and there will be reckoning.
Posted Mar 29, 2007 20:34 UTC (Thu)
by vondo (guest, #256)
[Link] (2 responses)
Just another reason to buy Canon. :-)
Posted Apr 2, 2007 21:33 UTC (Mon)
by pizza (subscriber, #46)
[Link]
A firestorm of controversy recently erupted when Thomas Knoll of Adobe accused Nikon of encrypting the white balance data in the D2X and D2Hs cameras, thus preventing Adobe from fully supporting these cameras.
Posted Dec 10, 2007 18:56 UTC (Mon)
by moxfyre (guest, #13847)
[Link]
... Or Pentax, which actually has adopted the Adobe DNG standard raw image format, for its latest K10D digital SLR!
Dave Coffin, author of dcraw, has high regard for DNG as a standard format: interview
Posted Mar 30, 2007 15:59 UTC (Fri)
by pointwood (guest, #2814)
[Link]
Posted Mar 29, 2007 11:47 UTC (Thu)
by jospoortvliet (guest, #33164)
[Link]
Anyway, I just read a blog about creating HDR pictures which you might find interesting: http://cyrilleberger.blogspot.com/2007/03/creating-hdr-im...
Posted Mar 29, 2007 15:25 UTC (Thu)
by paravoid (subscriber, #32869)
[Link] (2 responses)
It also has the goal to address missing feature from [WWW]dcraw like meta-data decoding and easy thumbnail extraction."
Author's blog[2] seems also interesting.
1: http://libopenraw.freedesktop.org/
Posted Mar 29, 2007 16:06 UTC (Thu)
by maderik (guest, #28840)
[Link] (1 responses)
Actually dcraw has thumbnail extraction ("-e" option) and support for the most common Exif fields. Another free (as in beer) program based on dcraw that runs under Linux (and Windows) is Raw Therapee.
dcraw is updated frequently (16 times since the beginning of the year). Keeping up with the changes is a major challenge for projects that do not just call the executable.
Posted Mar 29, 2007 20:26 UTC (Thu)
by vondo (guest, #256)
[Link]
I keep finding myself using the crappy Canon software for windows since it allows me to adjust sharpness, saturation, etc, and work in batches easily. (Pull up 100 images, tweak WB and exposure on a few, and then start a convert.) The user interface of this software leaves much to be desired, though.
I'd love to have a Linux replacement. I'll try these other two soon, but UFRaw just doesn't cut it.
Posted Mar 30, 2007 12:29 UTC (Fri)
by StuHerbert (guest, #15663)
[Link] (1 responses)
You need a better sensor to achieve a higher (or, strictly speaking, a *wider*) dynamic range. One such sensor is the specialist sensor used in the Fuji S5 Pro.
Best regards,
Posted Mar 30, 2007 13:06 UTC (Fri)
by corbet (editor, #1)
[Link]
In other words, the "more data between the top and bottom of the dynamic range" you mention is the dynamic range. It's what lets you record a bit more information about what's in the shadows without overexposing the image as a whole.
Posted Apr 4, 2007 0:37 UTC (Wed)
by roelofs (guest, #2599)
[Link]
Technically, that's not entirely true: JPEG/JFIF supports a 12-bit-per-sample mode, and libjpeg can even be compiled to support it (albeit as an all-or-nothing option--i.e., if you do that, you don't get 8-bit support anymore, at least not without third-party patches).
That said, I've never heard of a camera that can record 12bps JPEG, so it's sort of academic.
Greg
And the fork would be, obviously, the Foolish Editor series!How about a fork in the Grumpy Editor series?
It's a sad, sad world we live in where *reading an image file* could be described as `breaking in' to anything :(Working with raw images on Linux
Especially considering that the image file is NOT owned by the company that sold the camera, but by the person taking the picture, so why do they think they have a right to deny the photographer access to the data?Working with raw images on Linux
From what I understand in the Nikon situation they are contemplating (or trying) to deny the user access to the white balance data, not the actual sensor data. I guess Nikon could try to argue that those correction curves are their proprietary property.Working with raw images on Linux
To quote Dave Coffin (of dcraw fame)"Many manufacturers obfuscate their RAW data, including Canon.
I cracked this encryption on April 15, and updated dcraw.c and parse.c on April 17. So "dcraw -w" now works correctly with all Nikon cameras.
This is not a new problem. Phase One, Sony, Foveon, and Canon all apply some form of encryption to their RAW files. Dcraw decodes them all -- you can easily find decryption code by searching for the ^ operator.
Compression is not encryption. Phase One and Sony do encryption only. Kodak does compression only. Canon, Nikon, and Foveon compress the image data and encrypt some of the metadata.
Just another reason to buy Canon. :-)Working with raw images on Linux
I completely agree and this is probably the only major gripe I have about my Nikon D80. Nikon makes some great cameras, it is sad that they do something like this :(Working with raw images on Linux
Sad world indeed... It seems, in many cases, there aren't even real good reasons to keep ppl out of these files, except the thought that 'closed is better than open' from the companies...Working with raw images on Linux
I think libopenraw[1] is worth mentioning.libopenraw
"libopenraw is an ongoing project to provide a free software implementation for camera RAW files decoding. One of the main reason is that [WWW]dcraw is not suited for easy integration into applications, and there is a need for an easy to use API to build free software digital image processing application.
2: http://www.figuiere.net/hub/blog/?Libopenraw
dcraw, Raw Therapee
missing feature from dcraw like meta-data decoding and easy thumbnail extraction
There is also RawStudio which appears to handle multiple images.dcraw, Raw Therapee
Just a quick correction ... the dynamic range of an image is limited by the capabilities of the sensor, first and foremost. It isn't that RAW images have a *higher* dynamic range - the top and bottom of the range isn't different between RAW and JPEG. It's just that, having more bits per channel, RAW images have more data between the top and bottom of the dynamic range than an 8-bit JPEG image can hold.Dynamic range and file formats
Stu
I think we disagree slightly about what "dynamic range" means. It's not the difference between the upper and lower ends, instead, it's the ratio between the highest value and the smallest possible change you can represent. If you take 12-bit output from your sensor and cram it into an 8-bit file format (compressed or not) you've lost dynamic range.
Dynamic range and file formats
For people who like to play with HDR techniques there is an additional advantage: the camera typically record 12 to 16 bits of data for each channel - rather more than fits into a JPEG file.
12-bit JPEG