imshow() for multiple selected objects

Hi,
I have an image with ~200-250 labeled objects. How can I use imshow() to display multiple selected objects?
When I try this:
imshow(LL == 200)
It works to show the object labeled 200. Say I want to see 200 and 201. I tried:
imshow(LL == 200)
hold on
imshow(LL == 201)
This erases 200 and shows just 201.
Thanks for your suggestions and tips!

 Accepted Answer

11 Comments

Thanks- any idea how to use these to specify objects from a labelmatrix?
Can you clarify? Do you want to give different colors to each label? Can you attach the matrix?
Thanks- here are the following attachments:
  1. Image containing all the objects (colored by 'turbo' and 'shuffle' with label2rgb)- allobjects.png
  2. The labelmatrix of these objects- LLlabelmatrix.mat
  3. The RGB values from label2rgb- RGBvaluesfromlabel2rgb.mat
  4. The colormap I extracted, with the corresponding label in column1 - colormapandlabel.mat
I hope these clarify what I'm trying to do- I have many such images as allobjects.png in a time-series, and I'd like to give an object the same color it had in another image when it is correctly tracked between the images.
Thanks for taking a look!
By the way, imshow() works just fine to show one object (white, with black background). Just trying to figure out how to get it to show multiple labels at a time, with the right colors assigned by 'turbo'.
This code shows how you can use the colormap with image() to define the color of each region.
colormap(clmp(:, 2:end))
p = image(LL, 'CDataMapping', 'direct');
Thank you, Ameer Hamza! This works like a charm to give it the same colormap.
Can you explain a little about the logic behind 'CDataMapping'? I took a look at the documentation. It says:
"Color data mapping method, specified as 'direct' or 'scaled'. Use this property to control the mapping of color data values in CData into the colormap. CData must be a vector or a matrix defining indexed colors. This property has no effect if CData is a 3-D array defining true colors.
'direct' — Interpret the values as indices into the current colormap. Values with a decimal portion are fixed to the nearest lower integer.
If the values are of type double or single, then values of 1 or less map to the first color in the colormap. Values equal to or greater than the length of the colormap map to the last color in the colormap."
So if I understand this correctly, it assigns them the same map, but since the objects might move between frames, the object indices/labels change. If I can get the object labels to stay the same, in the same order, will it give each label the same color?
Yes, this is exactly what it means. It uses the label to decide which row of colormap to use. If you want to show two objects with the same color between frames, just give them the same label number.
  • The same label number and the same position/index in the list of labels? Or just the same label number?
  • Also, is there a way to set the zerocolor while using the image() command?
Thanks very much for all your help with this!
You only need the same label numbers in the 2D matrix and the same rows in the colormap. image() function just read the label value at a location in the matrix, go to that row in colormap and use that color.
According to documentation, by default, 0 value (or any negative value) is mapped to 1st color in the colormap. To give different color to 0, replace 0 with a different number. For example, currently, your matrix has 257 labels (if I remember correctly). Replace 0 with 258
LL(LL==0) = 258;
and then add a new row to the colormap too
cmap = clmp(:, 2:end);
cmap = [cmap; 0 0 0]; % black color is added at 258 row in colormap
colormap(cmap)
Thank you! I think I am beginning to follow the logic of how image() works. The trick is to find a way to get it to retain the labels while tracking the objects now.
I really appreciate all your help. Thanks again!
I am glad to be of help! :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!