0

I am doing Brain MRI segmentation using Fuzzy C-Means, The volume image is n slices, and I apply the FCM for each slice, the output is 4 labels per image (Gray Matter, White Matter, CSF and the background), how I can give the same label (Color) for each material for all the slices) I am using matlab

Thanks in advance

  • Why don't you apply the clustering to all voxels from all slices at once? – If this doesn't address your problem, you need to explain more precisely what you are trying to achieve, what you tried to do, and where you got stuck. – A. Donda May 01 '14 at 00:41
  • I am trying to segment Brain MRI volume image into 3 clusters (White matter, Gray Matter, and CSF), I tried to do what you said (To segment the whole volume) but I got error in the reshape function as follow:- Error using label2rgb Expected input number 1, L, to be two-dimensional. The code is shown in the main question above – user3591261 May 01 '14 at 01:16
  • Hard to tell without being able to run the code, but my guess is: Line 12 should say `numel(data)` instead of `length(data)`. – A. Donda May 01 '14 at 01:21

1 Answers1

0

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);
Raab70
  • 721
  • 3
  • 11