Retaining specific colors while tracking objects

1 次查看(过去 30 天)
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 个评论
Veena Chatti
Veena Chatti 2020-10-5
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.

请先登录,再进行评论。

回答(1 个)

Shashank Gupta
Shashank Gupta 2020-10-14
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.

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by