Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to draw thin line between different color regions?
Date: Tue, 27 Jan 2009 16:01:04 +0000 (UTC)
Organization: Queen's University
Lines: 23
Message-ID: <glnb40$lq1$1@fred.mathworks.com>
References: <gea0gi$nq2$1@aioe.org> <1d3ccafc-fd44-49cc-b289-f8c5f322f641@t42g2000hsg.googlegroups.com> <45e80e7d-08ae-4b57-b846-e656ae560989@s9g2000prm.googlegroups.com> <gln4v1$gfg$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233072064 22337 172.30.248.35 (27 Jan 2009 16:01:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 27 Jan 2009 16:01:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 943450
Xref: news.mathworks.com comp.soft-sys.matlab:514271


I'm neither sure that I've understood you all nor that I have coded this correctly, but you could try this function:

function im_labeled = image_labeller(im)
% IM is a 3 channel colour image, in which each colour corresponds to an
% object that should be labeled

% Get a num_pixels x 3 array - each row is a colour in the original image
x = reshape(im, size(im,1)*size(im,2), 3);

% Identify unique colours
[b, m, n] = unique(x, 'rows');

% Create the labels - a separate label for each colour
% (You might want to use 0:size(b,1)-1 instead)
labels = 1:size(b,1);

% Put the labels into a vector -
% check out the help for UNIQUE to get a better idea what's happening
im_labeled = labels(n);

% Reshape the vector to have the same dimensions as IM
im_labeled = reshape(im_labeled, size(im, 1), size(im, 2));