[Insight-users] multiplying a vnl_matrix with a vnl_vector

michiel mentink michael.mentink at st-hughs.ox.ac.uk
Wed Mar 31 06:56:09 EDT 2010


ok I found out that actual multiplication is no problem, my problem lies
with storing the end result.

This works:

  typedef itk::Matrix<double,3,4> Matrix3by4Type;
  typedef itk::Vector<double,4> Vector4Type;

  Matrix3by4Type Translation;
  Vector4Type FinalOrigin;

  Translation[0][0] = 1; Translation[0][1] = 0; Translation[0][2] = 0;
Translation[0][3] = 2;
  Translation[1][0] = 0; Translation[1][1] = 1; Translation[1][2] = 0;
Translation[1][3] = 3;
  Translation[2][0] = 0; Translation[2][1] = 0; Translation[2][2] = 1;
Translation[2][3] = 4;

  FinalOrigin[0] = 0; FinalOrigin[1] = 0; FinalOrigin[2] = 0; FinalOrigin[3]
= 1;

  std::cout << "finalorigin: " << std::endl << FinalOrigin << std::endl;
  std::cout << "translation: " << std::endl << Translation << std::endl;

  std::cout << "p :   "   << FinalOrigin   << std::endl ;
  std::cout << "A*p : " << Translation*FinalOrigin << std::endl ;


// but this doesn't work:

 FinalOrigin = A*p


When I make the vector a 1by4 Matrix instead:

FinalOrigin *= Translation;
 compile error: no match for 'operator*=' in 'FinalOrigin *= Translation'

 FinalOrigin *= Translation.GetTranspose();

runtime error:
vnl_matrix_fixed<T, num_rows, num_cols>::vnl_matrix_fixed(const
vnl_matrix<T>&) [with T = double, unsigned int num_rows = 4u, unsigned int
num_cols = 4u]: Assertion `rhs.rows() == num_rows && rhs.columns() ==
num_cols' failed.
(which makes sense because the the number of rows and colums of both the
vector and matrix are not the same)

So vector still seems to be the right way to go, I just can't figure out how
to save it in a vector...


Does anybody know how I save my result?

cheers, Michael




On Wed, Mar 31, 2010 at 10:21 AM, michiel mentink <
michael.mentink at st-hughs.ox.ac.uk> wrote:

>
> I'd like to do the following calculation, a translate:
>
> A =
> [ 1  0  0  2 ]
> [ 0  1  0  3 ]
> [ 0  0  1  4 ]
>
> B = [ x y z 1 ]
>
> FinalOrigin = A * B' = [x+2 y+3 z+4 ]
>
> For that, I have got the following code:
>
>
>
>   typedef itk::Matrix<double,3,4> Matrix3by4Type;
>   typedef itk::Vector<double,4> Vector4Type;
>
>   Matrix3by4Type Translation;
>   Vector4Type      FinalOrigin;
>
> FinalOrigin[0] = origin[0]; FinalOrigin[1] = origin[1]; FinalOrigin[2] =
> origin[2]; FinalOrigin[3] = 1;
> FinalOrigin = Translation * FinalOrigin;
>
>
>
> 1)
> Is it possible to multiply an itk::vector with an itk::matrix in ITK?
>
> 2)
> There is no transpose available for the vnl_vector type, that is
> implemented in ITK.
> Or is there?
>
>
> I know that there are other methods in ITK to do translation, but for my
> understanding, I'd like
> to figure this out.
>
> cheers,
>
> Michael
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100331/21a4224d/attachment.htm>


More information about the Insight-users mailing list