Retaining specific colors while tracking objects

조회 수: 1 (최근 30일)
Veena Chatti
Veena Chatti 2020년 10월 5일
답변: Shashank Gupta 2020년 10월 14일
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
KSSV
KSSV 2020년 10월 5일
Can't you specify the color while plotting. ?
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에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by