필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Not getting desired result ,any mistakes made by me in code,help me to rectify if any

조회 수: 1 (최근 30일)
Poonam
Poonam 2013년 9월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
  • * * This is mean shift segmentation code on color image * * *
function y = meanShiftseg(x,hs,hf,th,plotOn)
gray = 0;
if(size(x,3)==1)
gray = 1;
x = repmat(x,[1 1 3]);
end
if gray==0
s=rgb2hsv(x);
end
if gray==1
s=rgb2gray(x);
end
%%Argument Check
if nargin < 3
error('please type help for function syntax');
elseif nargin == 3
th = .25;
elseif nargin == 4
if th<0 || th >255
error('threshold should be in [0,255]');
else
plotOn = 1;
end
elseif nargin == 5
if sum(ismember(plotOn,[0,1])) == 0
error('plotOn option has to be 0 or 1');
end
elseif nargin>5
error('too many input arguments');
end
%%initialization
s =double(s);
[height,width,depth] = size(s);
y = s;
done = 0;
iter = 0;
%if plotOn
%figure randi(@x);
%end
% padding image to deal with pixels on borders
xPad = padarray(s,[height,width,0],'symmetric');
%%main loop
while ~done
weightAccum = 0;
yAccum = 0;
% only 99.75% area (3sigma) of the entire non-zero Gaussian kernel is considered
for i = -3*hs:3*hs
for j = -3*hs:3*hs
% spatial kernel weight
spatialKernel= exp(-(i^2+j^2)/(hs^2/2));
xThis = xPad(height+i:2*height+i-1, width+j:2*width+j-1, 1:depth);
xDiff = abs(y-double(xThis));
xDiffSq = xDiff.^2./hf^2;
% deal with multi-channel image
if depth > 1
xDiffSq = repmat(sum(xDiffSq,3),[1,1,depth]);
end
% feature kernel weight
intensityKernel = exp(-(xDiffSq)./2);
% mixed kernel weight
weightThis = double(spatialKernel).*double(intensityKernel).*double(xDiff);
% update accumulated weights
weightAccum = weightAccum+ weightThis;
% update accumulated estimated ys from xs
yAccum = double(yAccum)+double(xThis).*double(weightThis);
end
end
% normalized y (see Eq.(20) in the cited paper)
yThis = double(yAccum)./(double(weightAccum+eps));
% convergence criterion
yMSE = mean((double(yThis(:))-double(y(:)).^2));
if yMSE <= th % exit if converge
done = 1;
else % otherwise update estimated y and repeat mean shift
y = yThis;
iter = iter+1;
if plotOn
drawnow, imshow(uint8(y)),axis image, title(['iteration times = ' num2str(iter) '; mse = ' num2str(yMSE)]);
end
end
end
* * *The demo code is here* * *
im=imread(fullImageFileName);
c = meanShiftseg(im,8,10,5);
figure
subplot(231), imshow(im), title('Input Image')
subplot(233), imshow(c,[0,255]), title('Mean shift segmented Image')
This code works but the Problem is I am not getting the desired result
Here is the result
the result i am getting is not mean shift segmented image but a rgb 2 hsv
Please help me out to rectify my mistakes
  댓글 수: 1
Image Analyst
Image Analyst 2013년 9월 23일
Is this solved? You posted a later question where you seem to have good images, so I think this question is not applicable anymore.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by