0

I was wondering if someone can explain to me what this error means. And, if possible, how to resolve it? ??? Subscript indices must either be real positive integers or logicals.

Error in ==> interp2>linear at 344
F =  ( arg3(ndx).*(onemt) + arg3(ndx+1).*t ).*(1-s) + ...

Error in ==> interp2 at 220
zi = linear(ExtrapVal,x,y,z,xi,yi);

Error in ==> snake at 71
ssx = gamma*xs - kappa*interp2(fx,xs,ys);

This is my complete code:

image = imread('image.jpg');

%parameters
alpha = 0.001;
beta = 0.4;
kappa=0.0001;
gamma = 100;
N = 100; 
wl = 10;
we = 10;
wt = 10;
smth = rgb2gray(image);

% Calculating size of image
[row col] = size(image)

eline = smth; %eline is simply the image intensities

[grady,gradx] = gradient(double(smth));

eedge = -1 * sqrt ((gradx .* gradx + grady .* grady)); %eedge is measured by gradient in the image 

m1 = [-1 1];
m2 = [-1;1];
m3 = [1 -2 1];
m4 = [1;-2;1];
m5 = [1 -1;-1 1];

  cx = conv2(smth,m1,'same');
  cy = conv2(smth,m2,'same');
  cxx = conv2(smth,m3,'same');
  cyy = conv2(smth,m4,'same');
  cxy = conv2(smth,m5,'same');

  for i = 1:700
    for j= 1:900
    % eterm as deined in Kass et al Snakes paper
    eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j) -2 *cxy(i,j)*cx(i,j)*cy(i,j) +   cxx(i,j)*cy(i,j)*cy(i,j))/((1+cx(i,j)*cx(i,j) + cy(i,j)*cy(i,j))^1.5);
end
end

eext = (double(wl.*eline) + double(we.*eedge -wt) .* eterm); %eext as a weighted sum of eline, eedge and eterm

[fx, fy] = gradient(eext); %computing the gradient

xs=1:900;
xs=xs';
ys=repmat(242,1,900);
ys=ys'

[m n] = size(xs);
[mm nn] = size(fx);

%populating the penta diagonal matrix
A = zeros(m,m);
b = [(2*alpha + 6 *beta) -(alpha + 4*beta) beta];
brow = zeros(1,m);
brow(1,1:3) = brow(1,1:3) + b;
brow(1,m-1:m) = brow(1,m-1:m) + [beta -(alpha + 4*beta)]; % populating a template row
 for i=1:m
   A(i,:) = brow;
    brow = circshift(brow',1)'; % Template row being rotated to egenrate different rows in       pentadiagonal matrix
 end

 [L U] = lu(A + gamma .* eye(m,m));
 Ainv = inv(U) * inv(L); % Computing Ainv using LU factorization

 %moving the snake in each iteration
for i=1:N;

ssx = gamma * xs - kappa * interp2(fx,xs,ys); %This is where I receive the error
ssy = gamma * ys - kappa * interp2(fy,xs,ys);

%calculating the new position of snake
xs = Ainv * ssx;
ys = Ainv * ssy;


%Displaying the snake in its new position
 %     imshow(image,[]); 
 %     hold on;  
       plot([xs; xs(1)], [ys; ys(1)], 'r-');
 %     hold off;
 %     pause(0.001)    
        end;

2 Answers2

0

Sounds like you are trying to access position 0 or a non-integer (0.1) of an array, Matlab arrays start at position 1.

>> a=[1,2,3];
>> a(0)
??? Subscript indices must either be real positive integers or logicals.
>> a(1)

ans =

     1
Morgan
  • 19,934
  • 8
  • 58
  • 84
0

It seems like you provide interp2 with a vector xs instead of a matrix xs.

Also note that it is best not to use i and j as variables in Matlab.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • I don't have Matlab with me right now, so you'll have to give it a try yourself. You got an error from within `interp2` - so you must verify that you called it with proper arguments. – Shai Feb 20 '13 at 17:58