# Making voxels isotropic in (x,y,z) images

**URL:** https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186
**Category:** Visualization
**Tags:** question
**Created:** [February 14, 2024, 12:11am UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186 "2024-02-14T00:11:18Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![TheHedgehog2000](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@TheHedgehog2000](https://discourse.julialang.org/u/TheHedgehog2000)
#### Post date: [February 14, 2024, 12:11am UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/1 "2024-02-14T00:11:18Z")

</div>

Hi everyone,

I’ve started using Julia for processing microscopy data very recently (switching over from Python). My data tend to be 3D in space (meaning vertical stacks of images) and anisotropic (resolution in z is lower than in xy, due to, among other things, sampling). In Python, I make these stacks isotropic using scipy’s affine\_transform function ([scipy.ndimage.affine\_transform — SciPy v1.12.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html)); if one knows the necessary shape of the image after interpolation (i.e., with isotropic coordinates), then this can be applied straightforwardly. I have not been able to find a similar functionality in Julia. Does anyone have any suggestions? Maybe something similar is already implemented? I couldn’t find anything similar in the Images packages. Thanks!

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [February 14, 2024, 12:30am UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/2 "2024-02-14T00:30:32Z")

</div>

Perhaps you want to visualize a 3D grid with well-defined spacing. Check the GDSJL book for more info on how to create grids and visualize properties over it with Makie.jl:

[https://juliaearth.github.io/geospatial-data-science-with-julia](https://juliaearth.github.io/geospatial-data-science-with-julia)

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [February 14, 2024, 12:56am UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/3 "2024-02-14T00:56:24Z")

</div>

If you are looking for affine transforms, CoordinateTransformations.jl or ImageTransformations.jl may be what you need.

> **[GitHub - JuliaGeometry/CoordinateTransformations.jl: A fresh approach to...](https://github.com/JuliaGeometry/CoordinateTransformations.jl)**
>
> A fresh approach to coordinate transformations... Contribute to JuliaGeometry/CoordinateTransformations.jl development by creating an account on GitHub.

[https://juliaimages.org/ImageTransformations.jl/stable/](https://juliaimages.org/ImageTransformations.jl/stable/)

Also see this recording of the image processing workshop from JuliaCon 2023:

[![](https://global.discourse-cdn.com/julialang/original/3X/e/e/eece811f17822136179e66282fe9472150697feb.jpeg "Image Processing in Julia Workshop | JuliaCon 2023") ](https://www.youtube.com/watch?v=RWfAmIj4kS0)

@tim.holy , the presenter, also happens to be a microscopist. You might find some of his lab’s packages useful as well.

> **[Holy Lab](https://github.com/HolyLab)**
>
> None. Holy Lab has 52 repositories available. Follow their code on GitHub.

@RainerHeintzmann and his lab group also have some microscopy utilities available:

> **[RainerHeintzmann - Overview](https://github.com/RainerHeintzmann)**
>
> Physicist researching on optical microscopy. . RainerHeintzmann has 35 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [February 14, 2024, 12:32pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/4 "2024-02-14T12:32:11Z")

</div>

Here is practical example:

```julia
julia> using Meshes

julia> grid = CartesianGrid(10,10,10)
10×10×10 CartesianGrid{3,Float64}
  minimum: Point(0.0, 0.0, 0.0)
  maximum: Point(10.0, 10.0, 10.0)
  spacing: (1.0, 1.0, 1.0)

julia> sgrid = grid |> Scale(1,2,3)
10×10×10 CartesianGrid{3,Float64}
  minimum: Point(0.0, 0.0, 0.0)
  maximum: Point(10.0, 20.0, 30.0)
  spacing: (1.0, 2.0, 3.0)

julia> import GLMakie as Mke

julia> viz(grid, color = 1:1000)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/e/e/eeabe1d8736844253a2a0fdc30d94757b86ccc4c.png)

```julia
julia> viz(sgrid, color = 1:1000)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/38107f9f9efab299af614aee555f9993aafcd869.png)

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [February 14, 2024, 1:50pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/5 "2024-02-14T13:50:35Z")

</div>

You could take a look at [GitHub - SciML/DataInterpolations.jl: A library of data interpolation and smoothing functions](https://github.com/SciML/DataInterpolations.jl), which ought to give you what you need. I believe this should also handle irregular z sampling (1, 2, 4, 5, 8, …) but you could then interpolate in a pretty straightforward way.

---

<div class="post-metadata">

### Author: ![TheHedgehog2000](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@TheHedgehog2000](https://discourse.julialang.org/u/TheHedgehog2000)
#### Post date: [February 14, 2024, 3:02pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/6 "2024-02-14T15:02:30Z")

</div>

Thanks for the responses everyone! I’ll post here if I find a solution using any of the suggested packages.

---

<div class="post-metadata">

### Author: ![TheHedgehog2000](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@TheHedgehog2000](https://discourse.julialang.org/u/TheHedgehog2000)
#### Post date: [February 14, 2024, 6:51pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/7 "2024-02-14T18:51:24Z")

</div>

A convenient solution is the imresize function in the ImageTransformations package; it can perform the necessary upsampling along z given the aspect ratio of xy to z.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [February 14, 2024, 6:56pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/8 "2024-02-14T18:56:13Z")

</div>

You might also want to look into `WarpedView`. Instead of upsampling the entire volume eagerly, you just upsample on demand. This may be useful if you are dealing with large images with limited memory.

Just for reference, how large are your image stacks? I’m just trying to understand the scale of the problem.

---

<div class="post-metadata">

### Author: ![TheHedgehog2000](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@TheHedgehog2000](https://discourse.julialang.org/u/TheHedgehog2000)
#### Post date: [February 15, 2024, 11:25pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/9 "2024-02-15T23:25:39Z")

</div>

thanks for the suggestion! That indeed looks interesting. I’ll have to think about whether memory allocation is necessary for all the downstream analyses after making the voxels isotropic. The images aren’t that massive (at least compared to some other datasets I’ve seen) – at the most the dimensions would be something like 500x500x100 (anisotropic) voxels per image. But the data are also coming from a timelapse of up to 100 frames, so memory can occasionally be an issue.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [February 15, 2024, 11:35pm UTC](https://discourse.julialang.org/t/making-voxels-isotropic-in-x-y-z-images/110186/10 "2024-02-15T23:35:07Z")

</div>

Also I wanted to point out that we do have a forum section over at image.sc: [Topics tagged juliaimages](https://forum.image.sc/tag/juliaimages) in case you wanted to discuss this in a software agnostic fashion. I deal with problem a fairly frequently since I work with many people who with ImageJ and FIJI.
