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

%%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);

 採用された回答

cr
cr 2013 年 10 月 5 日

0 投票

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.

2 件のコメント

Poonam
Poonam 2013 年 10 月 5 日
Thank You got my expected result
Image Analyst
Image Analyst 2013 年 10 月 5 日
Then you changed your expected result. My answer would have given you the original expected result of having two color images appear blended, on top of one another. This answer says to get some kind of coordinates, for example using bwboundaries() or something, and then plotting them as lines in the graphical overlay. Still another way is to use methods discussed in Steve's blog: http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 10 月 4 日

0 投票

Why did you cast ovr from uint8, which will display fine, to double, which won't? Don't do that.

6 件のコメント

Poonam
Poonam 2013 年 10 月 4 日
still getting the same error
Image Analyst
Image Analyst 2013 年 10 月 4 日
what does "whos ovr" say?
Poonam
Poonam 2013 年 10 月 5 日
whos ovr
Name Size Bytes Class Attributes
ovr 142x190x6 161880 uint8
it is this what I get for whos ovr
cr
cr 2013 年 10 月 5 日
編集済み: cr 2013 年 10 月 5 日
It isn;t clear what you intend on the line above ovr=double... Looks like your tmp and ms are both rgb images or matrices of size MxNx3. On the line referred above you are concatenating them along third dim, you will get MxNx6 matrix as confirmed by whos. That is what imshow complains about.
Poonam
Poonam 2013 年 10 月 5 日
Yes MS and tmp are both rgb Image,Here I am trying to overlay the image on segmented image (which is segmented using mean shift) AS I need these further to create RAG graph so that I can Use it further for normalized cut segmentation
Here I did some changes but still getting the same error
% compute overlay image for display
ms=uint8(Ims);
tmp = uint8(I).*uint8(ms)>0;
ovr = uint8(cat(3,max(I, uint8(255*(ms==0))), tmp,tmp));
subplot(337),imshow(ovr);
Image Analyst
Image Analyst 2013 年 10 月 5 日
You can't show a 6 color channel image. You'd have to average them:
averagedImage = uint8((double(rgbImage1) + double(rgbImages2))/2);
imshow(averagedImage);

サインインしてコメントする。

質問済み:

2013 年 10 月 4 日

コメント済み:

2013 年 10 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by