
RAW files
The unprocessed digital output of an image sensor is called a RAW file. In this document we sometimes refer to it as Camera RAW to distinguish it from Bayer RAW files, which are standard image files that contain undemosaiced (Bayer) data.
New in Imatest 3.6: Generalized Raw read capability had been added. You can specify a file extension and read properties for files with this extension. The file will be interpreted as a Bayer RAW file. New in Imatest 3.5: the dcraw front-end interface has been updated to include an auto white level checkbox (should be unchecked for sensitivity measurements) and a gamma setting (the old defaults, 0.45 for bit depth = 8 and 1.0 or bit depth = 16 no longer apply.) |
The pixels in most digital image sensors are covered with a Bayer Color Filter Array (CFA), which makes each pixel sensitive to a single primary color, Red, Green, or Blue. The order of the colors is RGRGRG..., GBGBGB..., etc. There are twice as many greens as reds or blues because the eye is most sensitive to green. The four possible pixel arrangements (Red locations) are shown in the diagram below, where pixel locations start with Row 1 Column 1 (R1C1) in the upper left corner. There is no universal standard for mapping colors (R, G, or B) to pixel position (RmCn). The arrangement can be determined by examining a Bayer RAW image file with the Rawview utility, which can be called from a button on the right side of the Imatest main window.
|
|
||||||||||||||||||||||||||||||||
|
|
Most camera RAW formats are proprietary to the camera manufacturer (e.g., CR2 for Canon and NEF for Nikon) and must be converted into standard file formats (JPEG, TIFF, PNG, etc.) for most applications. This usually involves demosaicing, which is a form of interpolation that fills in the two missing colors in each pixel. Demosaicing is the primary function of RAW converter programs (which may be either built into the camera or installed on a separate computer). In demosaicing, detail in the missing colors is inferred from detail in other, neighboring colors. Algorithms can be very mathematically sophisticated. Demosaicing (RAW conversion) programs usually incorporate a number of secondary image processing steps, including
- applying a gamma curve, typically with a tonal response curve often applied on top of it,
- white balance and color adjustment,
- sharpening, usually in the neighborhood of contrasty features, and
- software noise reduction, typically in the absence of contrasty features.
All these steps can affect Imatest results. To minimize their effects, Imatest uses dcraw, a freely available program for converting RAW images to useful file formats. Dcraw applies simple gamma curves (with no additional tonal response curves) and does not perform sharpening or noise reduction.
RAW files in Imatest
Imatest can use RAW files in three ways. The first two use dcraw (which only works for RAW files from commercially-available cameras).
- It can demosaic RAW files, producing standard 3-color RGB image files in TIFF, PPM, PNG, or JPEG format, with TIFF as the default. The advantage of using dcraw is that it applies no sharpening, no noise reduction, and a straight gamma curve. Several choices are available for gamma, including 1/2.2 (for typical displays) and 1.0 (true linear). If RAW files are available, cameras and lenses from different manufacturers can be compared on a consistent, fair basis.
Dcraw should be used with caution in Colorcheck and Stepchart because is performs autoexposure by default. Starting with Imatest 3.5, the Auto white level button should be unchecked to turn off autoexposure (and get the correct levels). for 8/24-bit output. According to the dcraw FAQ, "No matter how dark an image is, dcraw's auto-exposure stretches it so that one percent of its pixels appear white. The "-W" option avoids this behavior." - It can convert camera RAW files into Bayer RAW files stored in standard monochrome image file formats (TIFF or PGM). Most Imatest Master modules can analyze Bayer RAW files. Bayer RAW is particularly valuable for measuring lateral chromatic aberration, which can be strongly distorted by the demosaicing process. Caution: dcraw may apply some tonal processing, even though the documentation indicates it shouldn't, i.e., gamma measured by Stepchart and other modules may not be close to 1, as it should be for an unprocessed Bayer RAW file.
- Generalized Raw Read can be used (introduced in Imatest 3.6-Beta). This is particularly useful for images from development systems and noncommercial applications not supported by dcraw. A file extension must be selected, and decoding parameters must be set up and saved, as described here.
- Click on an Imatest module (, , etc.) and open the file just as you would any other image file. If a camera RAW image file supported by dcraw (CR2, NEF, etc.— even Phase One RAW TIF files) is detected, the dialog box shown on the right for setting dcraw parameters is opened.
- Click on the box on the right side of the Imatest main window (or click Modules, Run dcraw) to run dcraw as a standalone application: the output file will be saved but no Imatest module will run. The dialog box on the right is a graphic user interface (GUI) front-end to dcraw that allows you to select several of dcraw's options.
| Vista users should select dcrawMS.exe in the Program box. |

dcraw dialog box
To use RAW files in Imatest, either
Dcraw can either (A) demosaic camera RAW files with minimal processing— no sharpening, no noise reduction, and a simple gamma curve, or (B) convert them to standard 8 or 16-bit monochrome file formats (TIFF or PGM) that contain Bayer RAW (undemosaiced) data, which can be analyzed by several Imatest Master modules. This conversion has the following choices:
| Demosaicing | Normal RAW conversion (demosaiced) |
| RAW 8-bit (Bayer RAW; no demosaicing) | |
| RAW 16-bit (Bayer RAW; no demosaicing) |
If the second or third option above (RAW 8-bit or RAW 16-bit) is selected, most the Demosaicing area (above) is grayed out and the output of dcraw is a monochrome TIFF or PGM file that contains undemosaiced (Bayer RAW) data from the image sensor. Note: the pixel levels and gammas of undemosaiced (Bayer RAW) files do not appear to be reliable as of July 2009. Levels are much too dark if Auto white level is unchecked, and the gamma is incorrect. Exposure and gamma are reliable with normal RAW conversion (with demosaicing).
Three separate dcraw programs are available.
| Program | dcraw | The original; may not work in Vista |
| LibRaw | dcraw emulator (works in Vista; no Bayer RAW) | |
| dcrawMS | Works in Vista |
DCrawMS.exe is a special build of dcraw designed to work with Vista. If you have a recent camera that doesn't work with dcraw or dcrawMS, try downloading the latest versions from Pukkita's Digital Darkroom Corner to the Imatest installation folder (C:\Program files\Imatest in most English language installations). LibRaw is a DLL library based on dcraw.

Bayer RAW files
When monochrome files are opened by an Imatest Master module that supports Bayer RAW analysis, the dialog box shown on the right appears. Standard monochrome file should be selected for regular monochrome files that do not contain Bayer RAW data. The color scheme of the buttons depends on the "Red in RmCn" selection, which affects some of the displays. The correct setting can be found using the Rawview utility.
Recognizing Bayer RAW patterns
Bayer RAW images are typically monochrome files (though they can be color if they are acquired using screen capture— Alt-PrtSc). They sometimes appear unexpectedly in development/prototyping systems. You can avoid serious headaches if you recognize them. They are characterized by square patterns similar to those shown on the right.
|
If Bayer RAW R1C1, R1C2, ... is selected, one of the four image planes starting with R1C1 (Row 1 Column 1), R1C2, R2C1, or R2C2 is selected for analysis. (Recall that there is no universal standard mapping an image plane with a color.) The four planes are shown below. Note that the pixel height and width of the image in each plane is half that of the image as a whole and the spacing between pixels is twice that of the sensor pixel spacing.
R1C1 ↓
|
R1C2 ↓
|
||||||||||||||||||||||||||||||||||||||||
R2C1 ↓
|
R2C2 ↓
|
(There is no universal standard for mapping colors to image plane.)
Demosaiced files with dcraw
The best way to be sure an image file faithfully resembles the RAW file— that it has a straight gamma curve, no sharpening, and no noise reduction— is to read a RAW file into Imatest and convert it to a standard format (TIFF, PPM, etc.) using Dave Coffin's dcraw. If you select any of the standard RAW formats (CRW, NEF, etc.) or if raw data is detected (e.g., Phase One TIF files) the dialog box shown above appears. It is a front-end to dcraw that allows you to choose between several RAW conversion options.
dcraw/dcrawMS conversion details:
If Normal RAW conversion (demosaiced) has been selected, the Demosaicing box contains several options, most of which are explained in more detail in the dcraw Manpage. The following output color spaces are available for demosaiced output.
| RAW (not true RAW pixels). Demosaiced with no color space conversion or White Balance. The camera's color profile is needed to correctly interpret the colors. Gamma = 0.45. |
| sRGB, Adobe RGB (1998), Wide Gamut RGB, ProPhoto RGB, and XYZ. |
Profile tags are embedded in the output file for the four standard color spaces. For 24-bit conversion, gamma appears to be fixed at 0.45, independent of the output color space. (It should be different for ProPhoto, which is designed for display at gamma = 1.8.) For 48-bit conversion gamma is fixed at 1 (linear conversion; does not correspond to standard color spaces). Several demosaicing quality levels (using different algorithms) are available (and worth exploring). See the dcraw Manpage for details.
Auto-exposure is always applied for 24-bit conversion (but not for 48-bit). I've changed the default to make it slightly darker than the dcraw default (using -b 0.99 in the command line) to reduce the likelihood of clipping pixels. For now we're stuck with auto-exposure for 24-bit conversion: see dcraw Frequently Asked Questions.
Dcraw converts RAW files into TIFF files, with the obscure PPM format available as an option. If check the box to delete the converted (TIFF) file, you may save the image in one of two compressed formats: PNG (lossless compression; takes longer) or JPEG (lossy compression; maximum quality; 24-bit only).
A list of supported cameras appears on the dcraw site. New cameras are typically added within one to three months of their introduction. The dcraw version included with Imatest sometimes falls behind. According to Dave Coffin, "Francisco Montilla provides Mac OS and Windows executables on his website. And Benjamin Lebsanft has volunteered to maintain Windows executables optimized for specific CPUs."
Rawview utility
The Rawview utility allows you to determine the color arrangement of Bayer RAW files (Red in R1C1, R1C2, R2C1, or R2C2) by trying each and selecting the one that looks best. The image can be saved as an RGB file if needed. It can be opened by pressing the button on the far right of the Imatest main window, just to the right of . When Rawview is first opened, instructions similar to those shown below appear. (They are likely to be more up-to-date.)
Welcome to Rawview. Preview Bayer RAW files.You can find the relationship between colors and pixel locations. Start by pressing "Read (Bayer) RAW image file." |
After the image file has been read, the Rawview window looks like this:

The Rawview window (no zoom)

The zoom function is always active: the image can be zoomed in to better view key details, like the red dots on the mirror, illustrated on the right, which only appear to be red when Red in R1C1 is selected. The button is enabled whenever the Red in RmCn selection is changed. It sets the default for opening Bayer RAW files in Imatest modules, affecting some displays.
Note that Rawview performs no White Balance, so the balance you see represents the color balance in the sensor, which may be of interest. It is rarely neutral.
Two options are available for saving images as an RGB files: saves the image as a low resolution RGB file using the R, (one of the) G, and B channels without demosaicing. The vertical and horizontal resolution is half that of the original file (total pixel count is 1/4 of the original). uses Malab's standard gradient-corrected linear interpolation demosaicing algorithm to save the image in a full resolution RGB file.
Rawview dropdown menus include display options and Save commands.
File
- Read Bayer RAW file Read the Bayer RAW file (must be in a standard image file format: TIFF, etc.)
- Save Screen Save the contents of the screen. Optionally display it if the Display screen checkbox is checked. You need to set the viewer before the first time you display the screen this way. Irfanview is an excellent free viewer.
- Save image as RGB file Save the image as an RGB file, which has half the pixel dimensions (resolution) on the original file. This does not involve a demosaicing algorithm. The contents of the R, selected G (G(R) or G(B)), and B channels are identical to the undemosaiced channels.
Settings
- Display G(R) as green Use the G(R) channel— the green pixels in the the same row as the red (R) pixels— for the green channel in the display and the RGB file save. You can tell if there is a difference between the two green channels (G(R) and G(B)) by toggling between these.
- Display G(B) as green Use the G(B) channel— the green pixels in the the same row as the blue (B) pixels— for the green channel in the display and the RGB file save.
- Display alternate greens Use G(R) and G(B) for alternate columns. Useful for narrowing the channel configurations from four to two in images that have no color reference (like the red dot): If the green channels are chosen incorrectly (R, B or B, R selected) the image may look striped.
- Adjust 16-bit images Brighten 16-bit images (which are linear or nearly so, i.e. gamma near 1.0) if needed to enhance display.
- Brighten 16-bit images Brighten 16-bit images further for additional display enhancement.
Help
- Online Help opens this page in your default web browser.
Generalized Read Raw
RAW files created by engineering development systems are rarely supported by dcraw. In many such cases you can read them (even if they're not standard image files) using Imatest's Read RAW capability. This new capability allows you to demosaic these files or to measure MTF of undemosaiced files (interpreted as standard monochrome files) when White Balance (WB) is applied.
Generalized Read Raw is mostly for files taken directly from prototype systems. For manufacturer's proprietary RAW formats, where, for example, four 12-bit pixels may be squeezed into 3 bytes, dcraw should be used.
To read generalized RAW files you must specify a file extension (up to five can be registered) and associate read parameters with that extension. This can be done in the following steps.
Click Settings, Read Raw setup. The following dialog box opens. Note that it's labeled Beta. Its capabilities will be enhanced through 2010. Entries should be based on manufacturer's data sheets, but some trial-and-error is usually required. If you make an incorrect choice, two plots will be displayed (below) to help determine the correct values.

Read Raw setup dialog box
- File extension. Select the extension index (1 through 5) with the dropdown menu on the left. (This number just selects which of the five extensions to work with.) Enter the extension (3 or more alphanumeric characters) in the box on the right. If possible, it should not be one of the extensions recognized by dcraw. The settings for this extension will be saved when you click OK or Test (which tests them by reading and displaying a file).
As of October 2009, the following extensions (listed in www.cybercom.net/~dcoffin/dcraw/rawphoto.c) are recognized by dcraw: 3fr, arw, bay, bmq, cine, cr2, crw, cs1, dc2, dcr, dng, erf, fff, hdr, ia, jpg, k25, kc2, kdc, mdc, mef, mos, mrw, nef, nrw, orf, pef, pxn, qtk, raf, raw, rdc, rw2, sr2, srf, sti, tif, and x3f. - Input pixel size How pixels are stored in the file. Choices are uint8, uint16, and uint32 (unsigned 8, 16, and 32-bit formats). In the future other formats may be added (more complex to implement), for example, for 2 12-bit pixels stored in 3 bytes.
- Output pixel size How pixels are stored in Imatest. Choices are uint8 or uint16.
- Bit shift The amount to shift bits: Auto or 0, ±2, ±4, ±6, or ±8. Usually needed to get correct levels for analysis. Negative numbers lighten the image.
- Byte ordering IEEE Little or Big-Endian. See wikipedia.org/wiki/Endian.
- Width Image width in pixels. Can usually be obtained from manufacturer's data sheets. If you enter an incorrect number for width and height (if Width x Height &un, two additional plots are displayed (see below) that help estimate the width.
- Height Image height in pixels.
- Transpose Switches rows and columns. Usually checked.
- Pixels to skip The number of pixels to skip at the start and end of the file.
- White balance None or Simple White Balance (gray world). Simple WB sets the gain on the four channels so their mean is identical (the lowest of the four means). It's not a sophisticated algorithm— it only works for mostly gray test charts (some color is tolerated as long as it averages to near-neutral gray). WB allows you to interpret the image as a standard monochrome file (rather than a Bayer RAW channel with only 1/4 the pixels) that can be analyzed for MTF with any of the sharpness modules (SFR, SFRplus, Log F-Contrast, Star Chart). A slanted edge without and with WB is shown below. White balance was not far off to begin with in this case.
![]() |
![]() |
|---|---|
| SFR edges: without and with White Balance | |
- White level No change or Auto: 99% of saturation. The Auto: 99% setting sets the highest pixel to 99% of the saturation level (252 for 8-bit files; 64880 for 16-bit files). This usually lightens the images, especially if Bit shift is not set to the optimum value.
- Help Opens this web page.
- Demosaicing Choose between none (Bayer raw output) or the Matlab's simple gradient-corrected linear interpolation demosaicing algorithm.
- Bayer arrangement (location of red channel).
- Output file Save the file (currently Bayer RAW-only) None (do not save; read-only), PNG file, or JPEG file. Files saved as PNG or JPG can be opened with Rawview.
- Test Saves the settings, then reads and displays a raw image file (example on right). If the actual size of the file read is not equal to the Pixel Width x Height, the image will be displayed with the same Width and an adjusted height and two diagnostic images (shown below; for estimating the correct width) are displayed. The text below the plot displays the specified Width, Height, and W x H and the actual number of pixels returned (which will equal W x H if the correct values have been chosen).
- OK Saves the settings and closes the Read Raw setup window.
- Cancel Closes the window. Does not save the settings.
Estimating image width and height
If the number of pixels read, excluding the skipped pixels at the beginning or end of the file, is not equal to the specified (Width x Height), two diagnostic plots are produced and the periodicity (normally equal to the pixel width) is estimated. The image on the right is what we get if we enter a deliberately incorrect value for Width (2590 instead of 2592). It's only a little off. Most of the time the resulting image is unintelligible.
The first added plot shows the levels of 215 = 32768 pixels near the middle of the file. It gives a good idea of the periodicity, but it's very difficult to read the exact number from this plot.

The second added plot estimates the periodicity (the most likely image width in pixels). It is derived by taking the fourier transform of the data in the first plot, calculating the absolute value (i.e., removing the phase), then taking the inverse fourier transform. The location of the first major peak (above 0) is the most likely periodicity. In this case it's 2592, shown on the upper right. This estimate may not work for all images. If necessary, you can zoom in by drawing rectangles around the region of interest. You may need to zoom in more than once to find the precise location of a feature. Double-click to zoom out.




