Peter111
Peter111

Reputation: 823

Eigen Block wrong amount of columns and rows

I have a Eigen Matrix with the size 256x256.

I want to shrink it to 100x100 and want to keep the inner values so the values from index 78,78 till 178,178.

I want to do this with the block operation but I get a matrix with a wrong size. The block has 178 rows and 178 columns instead of 100 rows and columns.

 Eigen::MatrixXf small = Eigen::MatrixXf::Constant(100, 100, 0.0);
 small = matrix.block(78, 78, 178, 178).eval();
 cout<<small.rows()<<endl;
 cout<<small.cols()<<endl;`

outputs 178 and 178.

What am I doing wrong?

Upvotes: 1

Views: 150

Answers (2)

As per documentation https://eigen.tuxfamily.org/dox/group__TutorialBlockOperations.html :

matrix.block(i,j,p,q); 

means

Block of size (p,q), starting at (i,j)

So you need, in your case p=q=100, hence something like

 small = matrix.block(78, 78, 100, 100).eval();

Upvotes: 4

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385405

You misread the documentation.

The third and fourth arguments are width and height, not X2 or Y2.

So, simply pass 100, 100 instead.

Upvotes: 4

Related Questions