Retaining specific colors while tracking objects
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Shashank Gupta
le 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.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!