The unprocessed digital output of an image sensor is called RAW image data. In this document we sometimes refer to raw files from commercial cameras or development systems as Camera RAW to distinguish them from Bayer RAW files, which are standard image files that contain undemosaiced (Bayer) data.
|New in Imatest 3.10: Pixel offset has been added to the Generalized read raw dialog.
The demosaicing algorithm can be selected in Read Raw (Matlab usually recommended).
New in Imatest 3.9: the dialog box that opens when monochrome files are read has been redesigned. This box lets you choose between a standard monochrome file, a Bayer RAW channel, or demosaic. RAW support has been generally strengthened.
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., in alternating rows. 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) at 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 opened from a button on the right side of the Imatest main window.
Red in R1C1
Red in R1C2
Red in R2C1
Red in R2C2
To be usable in most applications, RAW files must be demosaiced (though many Imatest modules can analyze RAW files directly if needed). Demosaicing (sometimes spelled demosaicking) a form of interpolation that fills in the two missing colors for each pixel. It 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. A good example (which may be the basis of Matlab’s gradient-corrected linear interpolation demosaic routine) is HIGH-QUALITY LINEAR INTERPOLATION FOR DEMOSAICING OF BAYER-PATTERNED COLOR IMAGES by Henrique S. Malvar, Li-wei He, and Ross Cutler of Microsoft.
In addition to demosaicing, converting RAW images into standard interchangeable image formats involves
- applying a gamma curve, often with an added tonal response curve (which often includes a “shoulder”),
- white balance and color (matrix) 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 (to convert RAW files without sharpening, noise reduction, and tonal response curves) Imatest uses the following techniques:
- For commercial RAW files, which are proprietary to camera manufacturers (e.g., CR2 for Canon and NEF for Nikon) and contain proprietary metadata that may be packed (m pixels into n bits), Imatest uses dcraw, a freely available program for converting commercial RAW images to useful file formats with minimal processing. Dcraw can apply simple gamma curves (with no additional tonal response curve).
- For the output of manufacturer’s development systems, which is typically pure binary data, 1 or 2 bytes per pixel, Imatest uses Generalized Read Raw, described below.
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), sRGB (close to gamma = 2.2, but with a linear region in the deep shadows), 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 (automatic white level adjustment) by default. The Auto white level button should be unchecked to get the correct levels. 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 (undemosaiced) 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 doesn’t, i.e., gamma measured by Stepchart and other modules may be quite different from the expected value of 1. (This may be due to processing in the RAW files themselves).
Windows 7/Vista users should select dcrawMS.exe in the Program box.
- Generalized Read Raw can be used for images from development systems and noncommercial applications not supported by dcraw. These images are generally not packed, i.e., pixels occupy 8 or 16 bits. A file extension must be selected, and decoding parameters must be set up and saved, as described here.
To use RAW files in Imatest, either
- Click on an Imatest module (SFR, Stepchart, etc.) and open the file just as you would any other image file. If the file extension indicates a camera RAW image file supported by dcraw (CR2, NEF, etc.— even Phase One RAW TIF files), the dialog box shown below for setting dcraw parameters is opened. If the file extension has been entered into Generalized Read Raw, the file will be read and decoded according to the Read Raw settings.
- Click on the dcraw 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 shown in the dcraw section below is a graphic user interface (GUI) front-end to dcraw that allows you to select several of dcraw’s options.
The best way to be sure an image file used by Imatest 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 settings window
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 too dark if Auto white level is unchecked, and the gamma is incorrect (for Canon RAW files). 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|
|dcrawMS||Works in Vista|
DCrawMS.exe is a special build of dcraw designed to work with Vista and Windows 7. 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).
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. Several demosaicing quality levels (using different algorithms) are available (and worth exploring). See the dcraw Manpage for details. Auto white level is the default. It should be turned off for tonal measurements.
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. Francisco Montilla provides Mac OS and Windows executables on his website.
When a monochrome file is opened by an Imatest Master module that supports Bayer RAW analysis, the dialog box shown below appears. (It was redesigned in Imatest 3.9.) should be selected for ordinary monochrome files that do not contain Bayer RAW data. For Bayer RAW files the color interpretation depends on the Pixel color mapping selection (Red in R1C1 for Canon; Red in R1C2 for Panasonic, etc.) The correct setting can be found by running the Rawview utility on an image with recognizable colors. Any of the four Bayer RAW color planes can be analyzed by selecting , , etc., or the image can be demosaiced by clicking . The demosaicing algorithm (standard Matlab (recommended) or lower quality bilinear demosaicing (only for specialized comparisons)) can be selected in the dropdown menu to the right.
This window appears whenever a monochrome file is opened.
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.
Bayer RAW characteristic patterns
If a Bayer RAW color has been selected, one of four image planes is selected, depending on Pixel color mapping and the button pressed (, , etc.). (There is no universal standard mapping an image plane with a color.) Four planes that could be analyzed for the button are shown below. Note that the height and width in pixels 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.
(There is no universal standard for mapping colors to image plane.)
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. 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.
There is no White Balance. Colors may appear faint.
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. The Imatest modules, affecting some displays.button is enabled whenever the Red in RmCn selection is changed. It sets the default for opening Bayer RAW files in
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.
- 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.
- 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.
- Brighter 16-bit images Brighten 16-bit images further for additional display enhancement.
- Online Help opens this page in your default web browser.
RAW files created by engineering development systems are rarely supported by dcraw, but in most cases you can read them (even if they’re not standard image files) using Imatest’s Read RAW capability. This 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 manufacturer’s development systems. For the proprietary RAW formats in commercial cameras, where data is packed, for example where four 12-bit pixels are 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. Entries should be based on manufacturer’s data sheets where possible, 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 width and height values.
Read Raw setup dialog box
- File extension. Select the extension index (1 through 8) with the dropdown menu on the upper-left. (This number selects which of the eight extensions to edit.) Enter the extension (3 or more alphanumeric characters) in the box on the right. If possible, it should be one of the extensions not recognized by dcraw. The settings for this extension will be saved when you click OK or Convert/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. Auto is usually recommended unless absolute levels are required.
|Warning: be cautious in applying bit shift, and especially Auto bit shift, to measurements that require absolute levels, particularly with 16-bit output files where the original sensor has 10-14 bits of data (resulting in padded files). Such measurements include hot/dead pixels (in Uniformity and Blemish Detect), Color Correction Matrix (in Multicharts), etc.|
- Pixel offset An integer number to subtract from the pixel levels. Used when there is a pixel level “pedestal”. Test carefully, especially when Bit shift is applied (it is applied before Bit shift).
- Byte ordering IEEE Little or Big-Endian. Affects results when Input pixel size is uint16. 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.
- Rotate/Mirror Allows the image to be rotated by multiples of 90 degrees and/or mirrored.
- 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; darken or lighten). 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), Matlab’s gradient-corrected linear interpolation demosaicing algorithm, or bilinear demosaicing (lower quality: for specialized comparisons-only).
- 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.