Assigning a colormap to bwlabel image representing imageprops

1 visualización (últimos 30 días)
Hello,
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
Ciaran

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 22 de Feb. de 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
end
cmap = jet(max(idx)); %a colormap
Lrgb = label2rgb(L,cmap); %build rgb image
imshow(Lrgb)
I used 'Orientation' instead of 'MajorAxisLength' because I couldn't think of a shipped image where that was distinguishing.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by