| Image Processing Toolbox |     ![]()  | 
Convert a label matrix into an RGB image
Syntax
RGB = label2rgb(L) RGB = label2rgb(L,map) RGB = label2rgb(L,map,zerocolor) RGB = label2rgb(L,map,zerocolor,order)
Description
RGB = label2rgb(L) converts a label matrix L, such as those returned by bwlabel or watershed, into an RGB color image for the purpose of visualizing the labeled regions. The label2rgb function determines the color to assign to each object based on the number of objects in the label matrix and range of colors in the colormap. The label2rgb function picks colors from the entire range. 
RGB = label2rgb(L,map) defines the colormap to be used in the RGB image. The colormap, map, can have any of the following values:
'jet' or 'gray' (See colormap for a list of supported colormaps.)
@jet or @gray 
If you do not specify map, the default value is 'colorcube'.
RGB = label2rgb(L,map,zerocolor) defines the RGB color of the elements labeled zero (i.e., the background) in the input label matrix L.  As the value of  zerocolor, specify an RGB triple or one of the strings listed in this table.
| Value | 
Color | 
'b' | 
blue | 
'c' | 
cyan | 
'g'  | 
green | 
'k' | 
black | 
'm' | 
magenta | 
'r' | 
red | 
'w' | 
white | 
'y' | 
yellow | 
If you do not specify zerocolor, the default value for zero-labeled elements is [1 1 1] (white).
RGB = label2rgb(L,map,zerocolor,order) controls how label2rgb assigns colormap colors to regions in the label matrix. If order is 'noshuffle' (the default), label2rgb assigns colormap colors to label matrix regions in numerical order. If order is 'shuffle', label2rgb assigns colormap colors pseudo-randomly. 
Class Support 
The input label matrix L can have any nonsparse, numeric class. It must contain finite, nonnegative integers. The output of label2rgb is of class uint8. 
Example 
I = imread('rice.tif'); figure, imshow(I), title('original image') BW = im2bw(I, graythresh(I)); L = bwlabel(BW); RGB = label2rgb(L); RGB2 = label2rgb(L, 'spring', 'c', 'shuffle'); imshow(RGB), figure, imshow(RGB2)
See Also
bwlabel, bwlabeln, ismember, watershed
   | isrgb | makelut | ![]()  |