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:
error with cross product

Subject: error with cross product

From: arron lacey

Date: 16 Mar, 2012 00:17:25

Message: 1 of 4

Hi guys, what's the error for here?

Img = imread('littlesquare.png');
Img = Img(:,:,1);
Img = double(Img);
[x,y] = size(Img);
I = ones(x,y);

 [R, L] = bwdist(Img);
 Rmag = bwdist(R);
 imshow(Rmag, []);
 B = cross(Img,Rmag);
 imshow(B)

I'm getting:

??? Error using ==> cross at 37
A and B must have at least one dimension of length 3.

even though imshow shows the expected image...

Subject: error with cross product

From: Roger Stafford

Date: 16 Mar, 2012 01:33:18

Message: 2 of 4

"arron lacey" <arronslacey@gmail.com> wrote in message <jju0ql$qjs$1@newscl01ah.mathworks.com>...
> Hi guys, what's the error for here?
>
> Img = imread('littlesquare.png');
> Img = Img(:,:,1);
> Img = double(Img);
> [x,y] = size(Img);
> I = ones(x,y);
>
> [R, L] = bwdist(Img);
> Rmag = bwdist(R);
> imshow(Rmag, []);
> B = cross(Img,Rmag);
> imshow(B)
>
> I'm getting:
>
> ??? Error using ==> cross at 37
> A and B must have at least one dimension of length 3.
>
> even though imshow shows the expected image...
- - - - - - - - -
  That error message means just what it says! One of the dimensions in each argument must have size 3. Cross products are really defined only in three-dimensional space. The cross product of two vectors in 3D is a third vector (also in 3D) orthogonal to those two vectors and having a length equal to the product of the two vectors' lengths times the sine of the angle between them and pointing in a right-hand sense. How are you going to define it with two images? Your code makes no sense. If you had left all three colors in, you would get a result though I am not sure what its significance would be.

Roger Stafford

Subject: error with cross product

From: arron lacey

Date: 16 Mar, 2012 11:15:22

Message: 3 of 4

"Roger Stafford" wrote in message <jju58u$9v9$1@newscl01ah.mathworks.com>...
> "arron lacey" <arronslacey@gmail.com> wrote in message <jju0ql$qjs$1@newscl01ah.mathworks.com>...
> > Hi guys, what's the error for here?
> >
> > Img = imread('littlesquare.png');
> > Img = Img(:,:,1);
> > Img = double(Img);
> > [x,y] = size(Img);
> > I = ones(x,y);
> >
> > [R, L] = bwdist(Img);
> > Rmag = bwdist(R);
> > imshow(Rmag, []);
> > B = cross(Img,Rmag);
> > imshow(B)
> >
> > I'm getting:
> >
> > ??? Error using ==> cross at 37
> > A and B must have at least one dimension of length 3.
> >
> > even though imshow shows the expected image...
> - - - - - - - - -
> That error message means just what it says! One of the dimensions in each argument must have size 3. Cross products are really defined only in three-dimensional space. The cross product of two vectors in 3D is a third vector (also in 3D) orthogonal to those two vectors and having a length equal to the product of the two vectors' lengths times the sine of the angle between them and pointing in a right-hand sense. How are you going to define it with two images? Your code makes no sense. If you had left all three colors in, you would get a result though I am not sure what its significance would be.
>
> Roger Stafford

I think there is a deeper problem than that. Even if I have:

Img = imread('littlesquare.png');
Img = Img(:,:,1);
Img = double(Img);
[x,y,z] = size(Img);
I = ones(x,y,z);
Rmag = bwdist(R);
imshow(Rmag, []);
    B = cross(Img,Rmag);


I still get the same error. I am beginning to think that bwdist does not return a vector field.....

Subject: error with cross product

From: Roger Stafford

Date: 16 Mar, 2012 19:48:18

Message: 4 of 4

"arron lacey" <arronslacey@gmail.com> wrote in message <jjv7ca$he7$1@newscl01ah.mathworks.com>...
> Rmag = bwdist(R);
> ......
> B = cross(Img,Rmag);
> ......
> I still get the same error. I am beginning to think that bwdist does not return a vector field.....
- - - - - - - - -
  The 'bwdist' routine only handles grey level images without color and that leaves you without any dimension of size 3 in Rmag. Therefore you cannot use 'cross' with it.

Roger Stafford

Tags for 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