0
votes

I have detected some objects on images from a sequence. For each frame ik I saved:

    IMG(ik,:)={centers, radii, metric, ik};

where centers is a n*2 array containing the 2D coordinates of the n circles I detected, radii is the values or their respective radii, metrics provides an info on the "quality" of this detection.

I would like to plot all these circles at once, on one image (which colormap is "gray"), with the color of these circle to correspond to the timestep (i.e. the value of ik). To do so I do the following:

    figure(2001)
    imagesc(averageIMG)
    axis equal
    colormap(gray)
    hold on
    cmap=jet(imgend-imgstart+1);
    for ik = 1:length(IMG)
        centers = IMG{ik,1};
        radii   = IMG{ik,2};
        viscircles(centers,radii,'Color',cmap(ik,:));
        hold on
    end

How can I plot a colorbar (with a jet colormap) that corresponds to the colors of the circles as an image of the timestep ik?

Note: I need to keep the colormap "gray" for the image that I use as a background of this plot.

Thank you for your help!

1

1 Answers

0
votes

This is tricky to be honest with you. What you want is two colorbars, I'm not sure if you want to plot both or just one of them. Now what you can do is to plot the colorbar before changing the colormap and get the limits

hcb=colorbar;
Limsgray=hcb.Limits; %I'm doing this because it's the easiest way to get the max value of the image if you don't know it. if do know the max value you don't necessarily have to do this part

And then add the max value of "Limsgray" to all of the values of the circles and set the set the 2nd (max) value of the limits of the colorbar to the "max values of the circle + max value of the image".
You'll also have to append the colormap so:

cg=colormap(gray);
cj=jet(imgend-imgstart+1);
cmap=[cg;cj];

You'll then have to add custom labels and ticks you can do this with

 hcb.TickLabels=[]; %removes tick labels if there's no text
hcb.Ticks=[]; %removes ticks if there are no numbers, so add your own

You can also add some spacing between the colorbars by adding a color like white between the gray and jet. If you only want to display 1, you just change the range by adjusting the limits and I suggest plotting the circles first and then appending the gray (but that's my opinion).

If you feel like it's too much effort or something, you can try this file but I think changing it is easier. Colorbar file at the exchange