Main Content

rawread

Read Color Filter Array (CFA) image from RAW file

    Description

    example

    cfaimage = rawread(filename) reads a CFA image from the RAW image file specified by filename.

    cfaimage = rawread(filename,Name,Value) specifies additional options with name-value arguments.

    Examples

    collapse all

    Read only the visible Color Filter Array (CFA) image data from a file. By default, rawread returns only the visible portion of the CFA image.

    cfa = rawread("colorCheckerTestImage.NEF");

    Read the entire CFA image from a file, including the image frame. In a RAW image, the frame is typically used to calculate the black-level surrounding the visible image.

    cfa = rawread("colorCheckerTestImage.NEF", "VisibleImageOnly", false);

    Input Arguments

    collapse all

    Name of RAW file, specified as a string scalar or char vector. Specify filename as a full path, containing the file name and extension, or as a relative path from the current folder or from any folder on the MATLAB path.

    Data Types: char | string

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: cfa = rawread("colorCheckerTestImage.NEF", "VisibleImageOnly",false);

    Return only visible CFA image data, specified as a logical scalar true or false. In a RAW image, the frame is typically used to calculate the black-level surrounding the visible image. To read only the visible portion of the CFA, specify true. To read the entire CFA, including the frame, specify false. This table provides more detail for each option.

    ValueDescription
    true (default)

    The dimensions of the cfaimage are VisibleImageSize(1)-by-VisibleImageSize(2)-by-P, where P is the number of planes.

    VisibleImageSize is a field in the ImageSizeInfo structure returned by rawinfo.

    false

    The dimensions of the cfaimage are CFAImageSize(1)-by-CFAImageSize(2)-by-P, where P is the number of planes.

    CFAImageSize is a field in the structure returned by rawinfo.

    Data Types: logical

    Output Arguments

    collapse all

    CFA image, returned as an M-by-N-by-P numeric array.

    By default, rawread returns only the visible portion of the CFA image. In this case, the values of M and N correspond to the first and second elements of the VisibleImageSize field reported by rawinfo, respectively. If you choose to include the frame in the returned image, the values of M and N correspond to the first and second elements of the CFAImageSize field reported by rawinfo, respectively. For both types of returned images, the value of P depends on the type of CFA sensor. For Bayer type sensors, the value is 1. For a Foveon sensor, the value is 3.

    Data Types: uint16 | single

    Limitations

    • The rawread function does not support RAW file formats that employ JPEG compression.

    More About

    collapse all

    Information about the RAW File Format

    The RAW file format preserves image data in its most unedited state, recorded directly from the camera sensor. Most camera manufacturers define their own proprietary RAW file format, such as the Nikon NEF file format and the Canon CRW format. Adobe has also defined a RAW file format, DNG (digital negative), which is supported by several cameras. The name of the format is typically capitalized, like other file formats such as JPG and TIF. However, unlike other file formats, RAW is not an acronym.

    Tips

    • The function uses LibRaw version 0.20.0 for reading the CFA image data.

    Introduced in R2021a