Is it possible to change numLabels manually when using labelvolshow?

Hi,
I adopted labelvolshow into custom function to show 3D time series data, but encountered a problem about colormap.
My data are these size
V = 483x496x5 double;
multiple same size and class Ln = 483x496x5 uint16;
the values in a L are given according to appearance time,
this makes my total numLabels is more than 2000 but only some of them in the same L.
(e.g: L346 is 483x496x5 uint16, the values for (x= 163:224, y= 120:189, z= 2:3) is 1966 )
The documentation said LabelColor accept numLabels-by-3, where numLabels represents the number of labels in the labeled volume
but I still give it a try
cmap = colormap(jet(numLabels));
hImage=labelvolshow(L, V,'Parent',P1, ...
'BackgroundColor',backgroundcolor, 'ScaleFactors', scalefact,...
'VolumeOpacity', volopacity, 'VolumeThreshold', volthreshold, 'LabelColor',cmap);
as expected, I got error message:
Error using labelvolshow
Expected LabelColor to be of size 8x3, but it is of size 2806x3.
So I want to know is there any suggestion/solution for my purpose?

1 Comment

I found myself not so clear in the original post that
I forgot to mention the shape of one label might change but the ID remains the same before disappearing.
So I don't want the colour for same labels change and I want different IDs with different colours in a short time period.
e.g: the orange, red and purple labels exist around t18 -> t19 -> tn
The biggest problem is the ID easily exceed the limit of colours for labelvolshow (recently I found it is 128) after t30.
All the labels become same colour.
I guess reusing colours is ok as long as these different labels can be distinguished by time
But I'm not sure how to do it.
Thanks

Sign in to comment.

Answers (1)

background_label = 0;
cmap = colormap(jet(numLabels));
%then for any particular L, V:
usedL = setdiff(unique(L), background_label);
hImage=labelvolshow(L, V,'Parent',P1, ...
'BackgroundColor',backgroundcolor, 'ScaleFactors', scalefact,...
'VolumeOpacity', volopacity, 'VolumeThreshold', volthreshold, 'LabelColor',cmap(usedL,:));
This assumes that there is a background label 0 that is to be ignored.

4 Comments

Dear Walter,
Thank you for your answer!
But this part makes the total colours are not enough for all labels.
usedL = setdiff(unique(L), background_label);
So I received error below:
Error using labelvolshow
Expected LabelColor to be of size 7x3, but it is of size 6x3.
Error in labelvolshow/set.LabelColor
I tried this
usedL = setdiff(unique(L)+1, background_label);
but I found all the labels become (almost) the same colour when the numLabels is very large so the difference in colormap is very little due to my cmap is
cmap = colormap(jet(numLabels));
Your solution gave me a hint but it is still not so clear for me so I haven't find out how to solve it. ha.
Okay, it appears that the background is handled as-if it is a "label" with its own color, but marked as transparent. So
usedL = unique(L);
colormap(jet(numel(usedL)))
hImage=labelvolshow(L, V,'Parent',P1, ...
'BackgroundColor',backgroundcolor, 'ScaleFactors', scalefact,...
'VolumeOpacity', volopacity, 'VolumeThreshold', volthreshold, 'LabelColor',cmap);
Dear Walter,
Thanks for your answer,
It seems the labelvolshow uses the real value in the L array.
e.g, 36th L array (which is also t36), there are 10 labels and their IDs are in the pic.
Although the cmap is set for 10 elements.
cmap = colormap(jet(numel(usedL)))
But the real value in L array exceed the limit of colours for labelvolshow (recently I found it is 128) and all labels become same colour.
By the way,
The volumeViewer cannot set different colours.
Even when I want to manually set colour for individual label, they change together.
I'll suggest MATHWORKS to improve 3D view

Sign in to comment.

Categories

Products

Release

R2021a

Asked:

on 22 Aug 2021

Commented:

on 7 Sep 2021

Community Treasure Hunt

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

Start Hunting!