Main Content


Transform color filter array (CFA) image in RAW file into RGB image

Since R2021a



    rgbImage = raw2rgb(filename) transforms the CFA image in the RAW file specified by filename into an RGB image.

    rgbImage = raw2rgb(filename,Name,Value) specifies additional options using name-value arguments.


    collapse all

    Convert the color filter array (CFA) image in the file into a 16-bit RGB image in the sRGB colorspace.

    rgb = raw2rgb("colorCheckerTestImage.NEF");

    Convert the CFA image into a 8-bit RGB image in the Adobe RGB 1998 colorspace.

    rgb = raw2rgb("colorCheckerTestImage.NEF",BitsPerSample=8,ColorSpace="adobe-rgb-1998");

    Convert the CFA image into a 16-bit image, in the camera's native colorspace, white-balanced against a D65 illuminant.

    rgb = raw2rgb("colorCheckerTestImage.NEF",ColorSpace="camera", ...

    Input Arguments

    collapse all

    Name of RAW file, specified as a string scalar or character 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.

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

    Data Types: char | string

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: rgb = raw2rgb("colorCheckerTestImage.NEF",BitsPerSample=8,ColorSpace="adobe-rgb-1998");

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: rgb = raw2rgb("colorCheckerTestImage.NEF","BitsPerSample",8,"ColorSpace","adobe-rgb-1998");

    Apply contrast stretching when rendering the RGB image, specified as a numeric or logical 0 (false) or 1 (true)

    Bits per sample of the output RGB image, specified as 8 or 16.

    Color space of the output RGB values, specified as "srgb", "camera", or "adobe-rgb-1998". For more information about the "srgb" and "adobe-rgb-1998" color spaces, see Understanding Color Spaces and Color Space Conversion. The "camera" color space is native to the device.

    Data Types: char | string

    White balance adjustment for rendering the RGB image, specified as one of the strings in this list, or as a 1-by-N vector of data type double.

    "AsTaken"White balance multipliers used by the camera to capture the image
    "D65"White balance multipliers required to balance image using the D65 illuminant
    "ComputeFromImage"White balance multipliers determined by analyzing the CFA image
    1-by-N vectorCustom white balance multipliers specified as a 1-by-N vector of data type single or double. For Bayer sensor images, N must be 4 and the order of the coefficients should match the CFALayout field reported by rawinfo. For non-Bayer sensors, N should match the SamplesPerPixel field reported by rawinfo.

    Data Types: double | char | string

    Output Arguments

    collapse all

    RGB image, returned as an M-by-N-by-3 numeric array. The values of M and N correspond to the first and second elements of the RenderedImageSize field reported by rawinfo, respectively.

    rgbImage can be either uint8 or uint16, depending on the value of the BitsPerSample name-value argument.

    Extended Capabilities

    Version History

    Introduced in R2021a

    expand all