Retaining specific colors while tracking objects

3 views (last 30 days)
Hi!
I'm using the watershed algorithm, combined with either 'turbo' or 'jet' to color detected objects.
thewatershedimage = label2rgb(watershedimage,'jet', [1 1 1], 'shuffle');
When I use it on a timeseries of images, I would like it to retain the same color for each object instead of shuffling it each time and assigning a new color.
Is there a straightforward way to do this?
Thanks!
  2 Comments
KSSV
KSSV on 5 Oct 2020
Can't you specify the color while plotting. ?
Veena Chatti
Veena Chatti on 5 Oct 2020
It's the "imshow(thewatershedimage)" command, not "plot(thewatershedimage)."
thewatershedimage = label2rgb(watershedimage,'jet', [1 1 1], 'shuffle');
The purpose of the "shuffle" is to ensure that the neighbors don't have a color gradient, and that the colors are shuffled for each of 200 objects within an image. When I track the object in multiple frames, I would like it to retain the same color it assigns to the object the first time it shuffles.

Sign in to comment.

Answers (1)

Shashank Gupta
Shashank Gupta on 14 Oct 2020
Hi Veena,
I tried taking a series of images with some motion and without changing anything in the function, the watershed function was able to give me the expected results. It is retaining the colors in the image, if you still facing the issue, would you like to describe your case more in detail? I tried small piece of code, check this out.
for i=1:10
center1 = -40;
center2 = -center1;
dist = sqrt(2*(2*center1)^2);
radius = dist/2 * 1.4;
lims = [floor(center1-1.2*radius) ceil(center2+1.2*radius)];
[x,y] = meshgrid(lims(1):lims(2));
bw1 = sqrt((x-center1-i*5).^2 + (y-center1-i*5).^2) <= radius-i*5;
bw2 = sqrt((x-center2-i*5).^2 + (y-center2-i*5).^2) <= radius-i*5;
bw3 = sqrt((x-center2-75).^2 + (y-center2-75).^2) <= radius-75;
bw = bw1 | bw2 | bw3;
% imshow(bw)
% title('Binary Image with Overlapping Objects')
D = bwdist(~bw);
D = -D;
L = watershed(D);
L(~bw) = 0;
rgb = label2rgb(L,'jet',[1 1 1],'shuffle');
figure();imshow(rgb)
end
Cheers.

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!