Main Content

colorize

Estimate color image of spectral image

Description

coloredImage = colorize(spcube) estimates a false-color image based on the three most informative bands when spcube is a hypercube object and an RGB image when spcube is a multicube object.

example

coloredImage = colorize(spcube,band) returns a false-color image using the specified spectral bands band.

[coloredImage,indices] = colorize(___) returns the indices of the bands used in the color image when spcube is a hypercube object.

___ = colorize(___,Name=Value) specifies options using one or more name-value arguments in addition to any combination of arguments from previous syntaxes. Use this syntax to specify the options to estimate false-colored and color-infrared (CIR) images of the input data.

Note

This function requires the Hyperspectral Imaging Library for Image Processing Toolbox™. You can install the Hyperspectral Imaging Library for Image Processing Toolbox from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

The Hyperspectral Imaging Library for Image Processing Toolbox requires desktop MATLAB®, as MATLAB Online™ and MATLAB Mobile™ do not support the library.

example

Examples

collapse all

Read a hyperspectral data into the workspace.

hcube = imhypercube("paviaU.dat");

Estimate a false-color image of the hyperspectral data.

coloredImg = colorize(hcube);

Display the false-color image.

imshow(coloredImg)

Figure contains an axes object. The hidden axes object contains an object of type image.

Download Landsat 8 multispectral data.

zipfile = "LC08_L1TP_113082_20211206_20211215_02_T1.zip";
landsat8Data_url = "https://ssd.mathworks.com/supportfiles/image/data/" + zipfile;
hyper.internal.downloadLandsatDataset(landsat8Data_url,zipfile)
filepath = fullfile("LC08_L1TP_113082_20211206_20211215_02_T1","LC08_L1TP_113082_20211206_20211215_02_T1_MTL.txt");

Read a multispectral image into the workspace.

mcube = immulticube(filepath);

Estimate an RGB image of the multispectral data. Increase the image contrast by applying contrast stretching.

coloredImg = colorize(mcube,ContrastStretching=true);

Display the contrast-stretched RGB image.

imshow(coloredImg)

Input Arguments

collapse all

Input spectral data, specified as a hypercube or multicube object representing a data cube of size M-by-N-by-C. C is the number of spectral bands.

If spcube is a multicube object and you are estimating an RGB image, the spectral bands nearest to the red, green, and blue wavelengths must have the same data resolution. If the red, green, and blue spectral bands of the multicube object do not have the same resolution, resample the bands using the resampleBands function.

Spectral band numbers, specified as a 3-element vector of positive integers. All elements of the vector must be unique and less than or equal to the total number of bands C in the input data. If spcube is a multicube object the selected spectral band must have the same data resolution. If the selected spectral bands of the multicube object do not have the same resolution, resample the bands using the resampleBands function or select other spectral bands have the same data resolution.

Data Types: double

Name-Value Arguments

collapse all

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.

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

Example: colorize(spcube,Method="rgb")

Method used to visualize the bands, specified as one of these options.

  • "falsecolored" — Create a false-color image consisting of the three most informative bands selected using selectBands function.

  • "rgb" — Create an RGB image by dividing the spectral range into red (R), green (G), and blue (B) bands. The red band ranges from 600 nm to 700 nm, the green band ranges from 500 nm to 600 nm, and the blue band ranges from 400 nm to 500 nm. The displayed R, G, and B channels consist of the most representative bands within the corresponding spectral range based on the correlation coefficient metric.

  • "cir" — Create a color-infrared (CIR) image by dividing the spectral range into near infrared (NIR), R, and G bands. The NIR band ranges from 760 nm to 960 nm, the red band ranges from 600 nm to 700 nm, and the green band ranges from 500 nm to 600 nm. The displayed channels consist of the most representative bands within the corresponding spectral range based on the correlation coefficient metric.

You can specify this name-value argument only when spcube is a hypercube object. To create RGB or CIR images, the Wavelength property of the hypercube object must have wavelengths in each of the corresponding ranges.

Data Types: char | string

Perform contrast stretching of the image, specified as a logical 0 (false) or 1 (true). When true, the colorize function applies contrast-limited adaptive histogram equalization, using the adapthisteq function.

Data Types: logical

Output Arguments

collapse all

Color image, returned as an M-by-N-by-3 numeric array. Each of the three color planes contains one band of the spectral image.

Data Types: single | double

Indices of the selected bands, returned as a 3-element column vector of positive integers.

Data Types: double

Version History

Introduced in R2020a