www.gusucode.com > images 案例代码 matlab源码程序 > images/ConvertLabelMatrixIntoAnRGBImageExample.m

    %% Use Color to Highlight Elements in a Label Matrix
% 
%%
% Read an image and display it.
%%

% Copyright 2015 The MathWorks, Inc.

I = imread('rice.png'); 
figure, imshow(I)
%%
% Create a label matrix from the image.
%%
BW = im2bw(I, graythresh(I)); 
CC = bwconncomp(BW);
L = labelmatrix(CC);
%%
% Convert the label matrix into RGB image, using default settings.
%%
RGB = label2rgb(L);
figure, imshow(RGB)
%%
% Convert label matrix into RGB image, specifying optional parameters.
%%
RGB2 = label2rgb(L, 'spring', 'c', 'shuffle'); 
figure, imshow(RGB2)