Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Out of bound Error

Subject: Out of bound Error

From: Jerome

Date: 20 Feb, 2013 15:21:08

Message: 1 of 6

I get the following error and I am unsure how to fix it. I tried to edit the rows and cols but it seems not to work. Does anyone know a quick fix to this problem:

??? Attempted to access cyy(1,901); index out of bounds because
size(cyy)=[700,900].

Error in ==> snake at 31
        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);


The following code is listed below:
image = imread(image.jpg);

%parameters
N = 100;
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:row
    for j= 1:col-1
        % 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

Subject: Out of bound Error

From: dpb

Date: 20 Feb, 2013 15:51:53

Message: 2 of 6

On 2/20/2013 9:21 AM, Jerome wrote:
> I get the following error and I am unsure how to fix it. I tried to edit
> the rows and cols but it seems not to work. Does anyone know a quick fix
> to this problem:
>
> ??? Attempted to access cyy(1,901); index out of bounds because
> size(cyy)=[700,900].
>
> Error in ==> snake at 31
> 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);
>
>
...

> [row col] = size(image);
...

> for i = 1:row
> for j= 1:col-1
> eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j)...
> end
> end

What does

size(image)

return? (Remove the ';' and rerun or use debug to stop and look)

col must be >901 for the loop index j to be 901. Or, of course, it's
possible the code that is being executed isn't what you're looking at
and have posted but a cached or aliased copy.

which snake % see where the actually-referenced copy is
clear snake % clear any cached copies

--

Subject: Out of bound Error

From: Jerome

Date: 20 Feb, 2013 16:00:21

Message: 3 of 6

The size of the image is : 700 x 2700

dpb <none@non.net> wrote in message <kg2rep$5p2$1@speranza.aioe.org>...
> On 2/20/2013 9:21 AM, Jerome wrote:
> > I get the following error and I am unsure how to fix it. I tried to edit
> > the rows and cols but it seems not to work. Does anyone know a quick fix
> > to this problem:
> >
> > ??? Attempted to access cyy(1,901); index out of bounds because
> > size(cyy)=[700,900].
> >
> > Error in ==> snake at 31
> > 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);
> >
> >
> ...
>
> > [row col] = size(image);
> ...
>
> > for i = 1:row
> > for j= 1:col-1
> > eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j)...
> > end
> > end
>
> What does
>
> size(image)
>
> return? (Remove the ';' and rerun or use debug to stop and look)
>
> col must be >901 for the loop index j to be 901. Or, of course, it's
> possible the code that is being executed isn't what you're looking at
> and have posted but a cached or aliased copy.
>
> which snake % see where the actually-referenced copy is
> clear snake % clear any cached copies
>
> --

Subject: Out of bound Error

From: Jerome

Date: 20 Feb, 2013 16:03:12

Message: 4 of 6

The size of the image: 700 x 2700.
dpb <none@non.net> wrote in message <kg2rep$5p2$1@speranza.aioe.org>...
> On 2/20/2013 9:21 AM, Jerome wrote:
> > I get the following error and I am unsure how to fix it. I tried to edit
> > the rows and cols but it seems not to work. Does anyone know a quick fix
> > to this problem:
> >
> > ??? Attempted to access cyy(1,901); index out of bounds because
> > size(cyy)=[700,900].
> >
> > Error in ==> snake at 31
> > 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);
> >
> >
> ...
>
> > [row col] = size(image);
> ...
>
> > for i = 1:row
> > for j= 1:col-1
> > eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j)...
> > end
> > end
>
> What does
>
> size(image)
>
> return? (Remove the ';' and rerun or use debug to stop and look)
>
> col must be >901 for the loop index j to be 901. Or, of course, it's
> possible the code that is being executed isn't what you're looking at
> and have posted but a cached or aliased copy.
>
> which snake % see where the actually-referenced copy is
> clear snake % clear any cached copies
>
> --

Subject: Out of bound Error

From: Jerome

Date: 20 Feb, 2013 16:10:24

Message: 5 of 6

The size of cyy however, is 700 x 900


"Jerome " <the_rome@hotmail.com> wrote in message <kg2pl4$803$1@newscl01ah.mathworks.com>...
> I get the following error and I am unsure how to fix it. I tried to edit the rows and cols but it seems not to work. Does anyone know a quick fix to this problem:
>
> ??? Attempted to access cyy(1,901); index out of bounds because
> size(cyy)=[700,900].
>
> Error in ==> snake at 31
> 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);
>
>
> The following code is listed below:
> image = imread(image.jpg);
>
> %parameters
> N = 100;
> 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:row
> for j= 1:col-1
> % 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

Subject: Out of bound Error

From: dpb

Date: 20 Feb, 2013 18:18:43

Message: 6 of 6

On 2/20/2013 10:00 AM, Jerome wrote:

...[top-posting repaired--don't; hard conversation follow makes]...

> dpb <none@non.net> wrote in message <kg2rep$5p2$1@speranza.aioe.org>...
>> On 2/20/2013 9:21 AM, Jerome wrote:
...
>> > ??? Attempted to access cyy(1,901); index out of bounds because
>> > size(cyy)=[700,900].
>> >
>> > Error in ==> snake at 31
>> > eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j) -2
...

>>
>> > [row col] = size(image);
>> ...
>>
>> > for i = 1:row
>> > for j= 1:col-1
>> > eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j)...
...

>> What does
>>
>> size(image)
>>
>> return? (Remove the ';' and rerun or use debug to stop and look)
>>
>> col must be >901 for the loop index j to be 901. Or, of course, it's
...

 > The size of the image is : 700 x 2700


Well, what do you expect then? You're asking to access from 1:col-1 for
columns in cyy() which has only 900 columns but image() is 3x the width.

One obvious fix (for this specific problem, anyway) would be to run the
loop over

[row,col=size(cyy);

but whether that has any bearing on the problem you're trying to solve
is anybody's guess--only you can know what it is you're attempting to
accomplish here.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us