Retaining specific colors while tracking objects
    조회 수: 6 (최근 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
답변 (1개)
  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.
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Basic Display에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


