Re: [ITK-users] vnl matrix to numpy array gives random numbers

Nick Cullen via Insight-users <[email protected]>
Newsgroups gmane.comp.lib.itk.user
Message-ID <[email protected]>
Oh and to be clear, it gives me random numbers <i>after</i> I hit the numpy view and such (i.e.g ndarrview  = numpy.asarray(memview).view(dtype = numpydatatype).reshape(shape).view(numpy.ndarray)) 

    On Monday, August 7, 2017 10:27 PM, Nick Cullen <nickmarch31-/[email protected]> wrote:
 

 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 !!!!

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.