[ITK-users] vnl matrix to numpy array gives random numbers
Nick Cullen
nickmarch31 at yahoo.com
Mon Aug 7 22:27:52 EDT 2017
Hi Friends !!
I'm trying to use itkPyVnl directly in ITK, but I must be getting something wrong with pointers... The following just gives me random numbers:
``` typedef typename ImageType::DirectionType ImageDirectionType; ImageDirectionType * direction = const_cast<ImageDirectionType *>( &image->GetDirection() );
typedef typename ImageDirectionType::InternalMatrixType DirectionInternalMatrixType; DirectionInternalMatrixType * fixed_matrix = const_cast<DirectionInternalMatrixType *>( &direction->GetVnlMatrix() );
const vnl_matrix<double> vnlmat1 = fixed_matrix->as_matrix(); vnl_matrix<double> * vnlmat2 = const_cast<vnl_matrix<double> *>( &vnlmat1 );
typedef itk::PyVnl<double> PyVnlType; PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat2 );```
I've tried a million different things and have problems either 1) due to the constness of ->as_matrix() and others or 2) due to "taking the address of a temporary object" with ->as_matrix() ... -__-
I know that this works:
``` vnl_matrix<double> * vnlmat = new vnl_matrix<double>; vnlmat->set_size(2,3); vnlmat->fill(0); vnlmat->put(1,2,1.3); vnlmat->put(1,0,2); std::cout << vnlmat << std::endl;
typedef itk::PyVnl<double> PyVnlType; PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat );```
Any help above is MUCH appreciated !!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20170808/ed72e86a/attachment.html>
More information about the Insight-users
mailing list