MATLAB Answers

Assigning a colormap to bwlabel image representing imageprops

11 views (last 30 days)
I would like to apply a colormap to a bwlabel image representing max axis length extracted by imageprops (max axis <50) of objects min - max (0 - 50) value.
The idea would be that the colormap would display the range of values on the image rather than simply a pseudorandom shuffle of colors.
I'd also like to be able to display an accompanying histogram of the binary objects with the same colormap arrangement.
How might this be achieved? At the moment I have the following which displays the pseudorandom colors
labelmax = bwlabel(keeperMaxImage, 8);
MaxRGB = label2rgb(L,'hot',[.5 .5 .5], 'shuffle');
figure, imshow(MaxRGB), title('Max Axis length - color ramp denotes range of lengths');
figure, hist(M_axis, 100), title('Max');
Kind Regards


Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 22 Feb 2013
Here's how I'd do it. There is probably a more elegant way:
%An image
I = imread('rice.png');
X = I>140; %binary
CC = bwconncomp(X); %Connected components
mal = regionprops(CC,'Orientation'); %Plug in MajorAxisLength here.
mal = vertcat(mal(:).Orientation); %Plug in MajorAxisLength here.
[~,idx] = histc(mal,0:ceil(max(mal))); %Which bin?
L = zeros(CC.ImageSize); %preallocate
for ii = 1:CC.NumObjects
L(CC.PixelIdxList{ii}) = idx(ii); %fill in indices
cmap = jet(max(idx)); %a colormap
Lrgb = label2rgb(L,cmap); %build rgb image
I used 'Orientation' instead of 'MajorAxisLength' because I couldn't think of a shipped image where that was distinguishing.

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.