MATLAB: Getting an Error and is not displaying Image,How to solve this

image segmentation

%%meanshift parameter
I was trying to make Region Adjacency Graph from MEAN SHIFT SEGMENTED Image
Got some Errors .Here is my code and my some result,help to fix the error
bw= 0.2; % Mean Shift Bandwidth
%%input
I = imread(fullImageFileName); % Original
%%ncut parameters
%SI = 5; % Color similarity
%SX = 6; % Spatial similarity
%r = 1.5; % Spatial threshold (less than r pixels apart)
%sNcut = 0.14; % The smallest Ncut value (threshold) to keep partitioning
%sArea = 220; % The smallest size of area (threshold) to be accepted as a segment
tic
[Ims Nms2]=Ms2(I,bw);
toc
subplot(331),imshow(I),title('Original Image');
subplot(332),imshow(Ims),title('Means Shifted Image');
tic
rg=rgb2gray(Ims);
subplot(333),imshow(rg);
level = graythresh(Ims); %# Compute an appropriate threshold
BW = im2bw(rg,level); %# Convert grayscale to binary
subplot(334),imshow(bw);
[labeledImage numberOfRegions] = bwlabel(BW);
subplot(335),imshow(labeledImage);
dist = bwdist(labeledImage);
subplot(336),imshow(dist);
% compute overlay image for display
ms=uint8(Ims);
tmp = uint8(double(I).*(ms>0));
ovr = uint8(cat(3, max(I, uint8(255*(ms==0))), tmp));
ovr=double(ovr);
subplot(441),imshow(ovr);
%[n,e]=imRAG(labeledImage);
  • Error *??? Error using ==> imageError using ==> imageIndexed CData must be size [MxN], TrueColor CData must be size [MxNx3]
Error in ==> basicImageDisplay at 9 hh = image(xdata,ydata,cdata, …
Error in ==> imshow at 248 hh = basicImageDisplay(fig_handle,ax_handle,…
Error in ==> NormalizeMeansegdemo at 111 subplot(337),imshow(ovr);

Best Answer

Concatenation is not the way to Overlay two images. imshow one image, hold on, and plot the segmented overlay on the same axes using plot function.