# How to perform change of basis from a non-orthogonal 3D array to an orthogonal 3D array ?

**URL:** <https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266>\
**Category:** Algorithms\
**Created:** [August 16, 2022, 2:57pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266 "2022-08-16T14:57:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)\
**Post date:** [August 16, 2022, 2:57pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/1 "2022-08-16T14:57:41Z")

</div>

I am trying to understand how to code the resampling of the voxels from a non-orthogonal basis as shown in the image below (taken from SimpleITK’s homepage) to an orthogonal grid.

 ![imageAsSpatialObjectConcept](https://discourse.itk.org/uploads/default/original/2X/d/d8c139fe8984a02b57b8d6780b7a2249e0716c11.png)

My input is say a 3D grayscale image/3D NumPy array (in a non-orthogonal grid) of dimensions MxMxM and I want to resample it onto an orthogonal grid of any dimensions (3D NumPy array). Can you tell me if it can be achieved by SimpleITK’s functions as well.

An example of a 2D slice (heatmap) of my 3D inputs is shown below. Basically those elliptical objects you see, will become circular post change of basis.  
 ![16085](https://discourse.itk.org/uploads/default/original/2X/7/7c6f2cc80f20132cb2d27e39714ce0203c79b898.png)

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [August 16, 2022, 4:48pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/2 "2022-08-16T16:48:54Z")

</div>

Hello @pranoy-ray,

Yes, this is readily done using SimpleITK.

For specific code, please see the `make_isotropic` function in [this jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/05_Results_Visualization.ipynb).

---

<div class="post-metadata">

**Author:** ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)\
**Post date:** [August 16, 2022, 6:43pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/3 "2022-08-16T18:43:57Z")

</div>

@zivy Thank You for your reply, but how do I cast a 3D NumPy array to an Sitk object, which can be passed it into the make\_isotropic function?

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [August 16, 2022, 7:16pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/4 "2022-08-16T19:16:57Z")

</div>

Hello @pranoy-ray,

To get a SimpleITK image from a numpy array:

```auto
image = sitk.GetImageFromArray(numpy_array)

```

For full details see [this jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/03_Image_Details.ipynb).

---

<div class="post-metadata">

**Author:** ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)\
**Post date:** [August 16, 2022, 8:42pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/5 "2022-08-16T20:42:42Z")

</div>

The make\_isotropic() function isn’t working as planned.

Input Image 2D Slice:

 ![Screen Shot 2022-08-16 at 4.40.35 PM](https://discourse.itk.org/uploads/default/original/2X/d/d71aa6b68fafd088d5572f2859ddae68e5534751.jpeg)

Output Image 2D Slics:

 ![Screen Shot 2022-08-16 at 4.41.10 PM](https://discourse.itk.org/uploads/default/original/2X/6/6c73df409ee28152f12ed3cbc0e815a26e48775a.jpeg)

---

<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:** [August 16, 2022, 8:55pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/6 "2022-08-16T20:55:07Z")

</div>

> [@zivy](#):
>
> `image = sitk.GetImageFromArray(numpy_array)`

This will assume orthogonal axes. You need to provide the actual vectors via `SetDirection()`.

---

<div class="post-metadata">

**Author:** ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)\
**Post date:** [August 17, 2022, 8:07pm UTC](https://discourse.itk.org/t/how-to-perform-change-of-basis-from-a-non-orthogonal-3d-array-to-an-orthogonal-3d-array/5266/7 "2022-08-17T20:07:15Z")

</div>

Hi @dzenanz@zivy I did what you guys said, but it doesn’t seem to do the basis transformation.

Assuming “data\_3d” is the 3D NumPy array containing my 3D image (Primitive Cell FCC Lattice-Voxelized), my code is as follows:

```auto
image = sitk.GetImageFromArray(data_3d)
image.SetDirection(tuple((0.5, 0.5, 0.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.5)))
un=make_isotropic(image)    
sitk.Show(un,"Final Data")

```

Trying to make the transformation from non-orthogonal basis (60,60,60) to orthogonal basis (90,90,90)

Please can you tell me where I’m going wrong?
