Getting following error,help to rectify it

1 Ansicht (letzte 30 Tage)
Poonam
Poonam am 9 Mär. 2015
Beantwortet: Jan am 9 Mär. 2015
function [y, MS] = meanShiftPixCluster(x,hs,hr,th,plotOn)
% FUNCTION: meanShiftPixCluster implements the classic mean shift pixel
% clustering algorithm introduced in Cmaniciu etal.'s PAMI paper
% "Mean shift: a robust apporach toward feature space analysis", 2002.
% -------------------------------------------------------------------------
% Input:
% x = an input image (either gray or rgb, please expect long time processing if image size is large)
% hs = the bandwidth of spatial kernel (see Eq.(35) in the cited paper)
% hr = the bandwidth of feature kernel (see Eq.(35) in the cited paper)
% th = the threshod of the convergence criterion (default = .25)
% plotOn = switch on/off the image display of intermediate results (default = 1)
%
% Output:
% y = the output pixel clustered image
% MS = the output of averaged mean shift
% -------------------------------------------------------------------------% -------------------------------------------------------------------------
%%Argument Check
if nargin<3
error('please type help for function syntax')
elseif nargin == 3
th = 1/100; plotOn = 1;
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
x = double(x);
[height,width,depth] = size(x);
y = x;
done = 0;
iter = 0;
if plotOn
figure(randi(1000)+1000);
end
% padding image to deal with pixels on borders
xPad = padarray(x,[height,width,0],'symmetric');
% build up look up table to boost computation speed
weight_map = exp( -(0:255^2)/hr^2 );
MS = [];
%%main loop
while ~done
weightAccum = 0;
yAccum = 0;
% only 99.75% area (3sigma) of the entire non-zero Gaussian kernel is considered
for i = -hs:hs
for j = -hs:hs
if ( i~=0 || j~=0 )
% spatial kernel weight
%spatialKernel = 1;
% uncomment the following line to active Gausian kernel
spatialKernel = exp(-(i^2+j^2)/(hs/3)^2/2);
xThis = xPad(height+i:2*height+i-1, width+j:2*width+j-1, 1:depth);
xDiffSq = (y-xThis).^2;
% feature kernel weight
intensityKernel = repmat( prod( reshape( weight_map( xDiffSq+1 ), height, width, depth) , 3 ), [1,1, depth]);
% mixed kernel weight
weightThis = spatialKernel.*intensityKernel;
if true
% code
end
% update accumulated weights
weightAccum = weightAccum+ weightThis;
% update accumulated estimated ys from xs
yAccum = yAccum+xThis.*weightThis;
end
??? Subscript indices must either be real positive integers or logicals.
Error in ==> meanShiftPixCluster at 65 intensityKernel = repmat( prod( reshape( weight_map( xDiffSq+1 ), height, width, depth) , 3 ), [1,1, depth]);

Antworten (1)

Jan
Jan am 9 Mär. 2015
The error message means, that xDiffSq is either smaller than -1 or does not have integer values.
Use the debugger to find out more details:
dbstop if error
Then run the code again and inspect the values of the locally used variables.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by