LABEL2RGB Convert label matrix to RGB image.
RGB = LABEL2RGB(L) converts a label or a categorical matrix L, into a
color RGB image for the purpose of visualizing the labeled regions.
RGB = LABEL2RGB(L, MAP) defines the colormap to be used in the RGB
image. MAP can either be an n x 3 colormap matrix, a string or a
character vector containing the name of a colormap function (such as
'jet' or 'gray'), or a function handle of a colormap function (such as
@jet or @gray). LABEL2RGB evaluates MAP so that there is a different
color for each region in L. If MAP is not specified, 'jet' is used as
the default.
RGB = LABEL2RGB(L, MAP, ZEROCOLOR) defines the RGB color of the
elements labeled 0 or <undefined> in the input label matrix L.
ZEROCOLOR can either be an RGB triple, or one of the following: 'y'
(yellow), 'm', (magenta), 'c' (cyan), 'r'(red), 'g' (green), 'b'
(blue), 'w' (white), or 'k' (black). If ZEROCOLOR is not specified, [1
1 1] is used as the default.
RGB = LABEL2RGB(L, MAP, ZEROCOLOR, ORDER), controls how colormap colors
are assigned to regions in the label matrix. If ORDER is 'noshuffle'
(the default), then colormap colors are assigned to the label matrix
regions in numerical order. If ORDER is 'shuffle', then colormap
colors are pseudorandomly shuffled.
RGB = LABEL2RGB(...,Name,Value) specifies additional name-value pair
arguments described below:
'OutputFormat' Specify the output format. Valid values are:
'image' The output is an M-by-N-by-3 image
where M-by-N is the size of the input
label matrix.
'triplets' The output is an M-by-3 matrix where
each row is an 1-by-3 RGB triplet and
M is the number of elements in the
input label matrix.
Specify this value when you want to
convert a list of labels into a list
of RGB colors.
Default: 'image'
Class Support
-------------
The input label matrix L can be numeric or categorical. When L is
numeric, it must contain finite nonnegative integers. RGB is uint8.
Example 1
---------
%Use label2rgb to customize display of label matrix.
I = imread('rice.png');
figure, imshow(I)
BW = imbinarize(I);
CC = bwconncomp(BW);
L = labelmatrix(CC);
RGB = label2rgb(L);
RGB2 = label2rgb(L, 'spring', 'c', 'shuffle');
figure, imshow(RGB), figure, imshow(RGB2)
Example 2
---------
%Use label2rgb to display categorical label matrix.
load('buildingPixelLabeled','label');
RGB = label2rgb(label);
figure, imshow(RGB)
See also BWCONNCOMP,BWLABEL,COLORMAP,ISMEMBER,LABELMATRIX,WATERSHED.
Documentation for label2rgb
doc label2rgb