# How to calculate eigen values and eigen vectors of an image

**URL:** https://discourse.itk.org/t/how-to-calculate-eigen-values-and-eigen-vectors-of-an-image/5361
**Category:** Community
**Created:** [September 25, 2022, 4:13am UTC](https://discourse.itk.org/t/how-to-calculate-eigen-values-and-eigen-vectors-of-an-image/5361 "2022-09-25T04:13:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cnkhanh](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://discourse.itk.org/u/cnkhanh)
#### Post date: [September 25, 2022, 4:13am UTC](https://discourse.itk.org/t/how-to-calculate-eigen-values-and-eigen-vectors-of-an-image/5361/1 "2022-09-25T04:13:16Z")

</div>

I tried to calculate eigen values and eigen vectors of an image by getting the array of the image

```auto
img = sitk.ReadImage("data/image.mhd")
img_arr = sitk.GetArrayFromImage(img)

w, v = numpy.linalg.eig(img_arr)

```

But I got an error “LinAlgError: Last 2 dimensions of the array must be square”.

How can I canculate the eigen values and eigen vectors ?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 26, 2022, 1:28pm UTC](https://discourse.itk.org/t/how-to-calculate-eigen-values-and-eigen-vectors-of-an-image/5361/2 "2022-09-26T13:28:04Z")

</div>

Square matrices have eigenvectors and eigenvalues. Interpreting an image as a matrix usually does not have much sense. What are you trying to accomplish?

The error is saying that the image you are passing should have equal sizes along X and Y dimensions (technically, `i` and `j` indexing axes).

---

<div class="post-metadata">

### Author: ![cnkhanh](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://discourse.itk.org/u/cnkhanh)
#### Post date: [September 26, 2022, 1:33pm UTC](https://discourse.itk.org/t/how-to-calculate-eigen-values-and-eigen-vectors-of-an-image/5361/3 "2022-09-26T13:33:56Z")

</div>

I tried to get the eigen vector and eigen value of the input image
