Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Poonam
Poonam le 23 Sep 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
  • * * 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 commentaire
Image Analyst
Image Analyst le 23 Sep 2013
Is this solved? You posted a later question where you seem to have good images, so I think this question is not applicable anymore.

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by