Assuming your FCM function is working correctly it should output the same 4 label values for each slice, for example [0 1 2 3]
. Really this is a display issue and has nothing to do with the actual segmentation. If the labels are being output as different values that is another problem. This can be accomplished with label2rgb
as the documentation suggests here. I would probably use this form:
RGB = label2rgb(L, map)
Where map is a colormap. If you pass the same map
to each slice's call to label2rgb
the labels will be returned with the same colors. This can also be implemented relatively easily. Assume your labels are [0,1,2,3]
and you have a variable labels
with your label image, and you could do:
% //define your own custom colormap to be whatever you like
cmap = [1 1 1; ...% //white
1 0 0; ...% //red
0 1 0; ...% //green
0 0 1]; % //blue
labelVisSlice = zeros(size(labels,1),size(labels,2),3); % //make mxnx3 array
tmp1=labelVisSlice(:,:,1);
tmp2=labelVisSlice(:,:,2);
tmp3=labelVisSlice(:,:,3);
% //now loop over all the labels and fill in the colors.
for label=1:length(unique(labels))
labeledVoxels = labels==label;
% //I'm sure there is a much faster way to do this but It's not coming to mind
tmp1(labeledVoxels)=cmap(label+1,1);
tmp2(labeledVoxels)=cmap(label+1,2);
tmp3(labeledVoxels)=cmap(label+1,3);
end
labelVisSlice=cat(3,tmp1,tmp2,tmp3);
imagesc(labelVisSlice);