# Set Image Direction from numpy array

**URL:** https://discourse.itk.org/t/set-image-direction-from-numpy-array/844
**Category:** Beginner Questions
**Tags:** python
**Created:** [April 18, 2018, 9:47am UTC](https://discourse.itk.org/t/set-image-direction-from-numpy-array/844 "2018-04-18T09:47:06Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 26, 2018, 2:18pm UTC](https://discourse.itk.org/t/set-image-direction-from-numpy-array/844/6 "2018-04-26T14:18:24Z")

</div>

> [@matt.mccormick](#):
>
> @T4mmi could you please save eigenVectors and share them?

Here is the matrix

[eigenVectors.npy](https://discourse.itk.org/uploads/default/original/1X/73a5321bebc99c812a5e19d08c6efa7381bbaf23.npy) (200 Bytes)

I obtain it from the following :

```auto
# Main axes computation
objectImageFilter.Update()
mainConnComp = itk.GetArrayViewFromImage(objectImageFilter.GetOutput())
pointsCoords = numpy.asarray(numpy.where(mainConnComp)).T
# rotationCenter = [round(i/2) for i in mainConnComp.shape] # rotate around the image center
rotationCenter = [int(i) for i in numpy.mean(
    pointsCoords, axis=0)] # rotate around the object center
covarianceMatrix = numpy.cov(pointsCoords, rowvar=False)
pointsCoords = None
eigenValues, eigenVectors = numpy.linalg.eigh(covarianceMatrix)
covarianceMatrix = None
descendantIndices = numpy.argsort(eigenValues)[::-1]
eigenVectors = eigenVectors[:, descendantIndices] 

```

---

_[View the full topic](https://discourse.itk.org/t/set-image-direction-from-numpy-array/844)._
