# Images - Kernel sizes and ImageAxes

**URL:** <https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/41858>\
**Category:** General Usage\
**Tags:** images\
**Created:** [June 22, 2020, 1:29pm UTC](https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/41858 "2020-06-22T13:29:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirestrepo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirestrepo/32/617_2.png) [@mirestrepo](https://discourse.julialang.org/u/mirestrepo)\
**Post date:** [June 22, 2020, 1:29pm UTC](https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/41858/1 "2020-06-22T13:29:26Z")

</div>

Hi All,

This is probably a naive question. Given an image stack with z-spacing that is not the same as x and y, what is the correct way to handle the size for example of the `σshape` for the laplacian of gaussian? I have always compensated for that in the size of the filter… i.e., `σshape = [1.0, 1.0, 0.5]` - but I’m wondering if I should instead be leveraging ImageAxes to set the units, and then the σshape is simply `[1,1,1]` ? I guess I’m confused on how the setting the units for the axes affects the sizes for the filters.

Thanks in advance for any guidance!

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [June 22, 2020, 3:04pm UTC](https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/41858/2 "2020-06-22T15:04:42Z")

</div>

Image filtering doesn’t take axis sizing into account:

```julia
julia> img = AxisArray(zeros(3, 5),
                       Axis{:x}(1mm:2mm:5mm),
                       Axis{:y}(1mm:1mm:5mm)); img[2, 3] = 1;

julia> img
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, (1:2:5) mm
    :y, (1:5) mm
And data, a 3×5 Array{Float64,2}:
 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 1.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0

julia> imfilter(img, Kernel.LoG((0.25, 0.25)))
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, (1:2:5) mm
    :y, (1:5) mm
And data, a 3×5 Array{Float64,2}:
 0.0 0.000137553 0.191352 0.000137553 0.0
 0.0 0.191352 -81.4873 0.191352 0.0
 0.0 0.000137553 0.191352 0.000137553 0.0

```

It’d be nice if it did, though! I just opened an issue for this: [https://github.com/JuliaImages/ImageFiltering.jl/issues/176](https://github.com/JuliaImages/ImageFiltering.jl/issues/176)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 23, 2020, 8:11pm UTC](https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/41858/3 "2020-06-23T20:11:26Z")

</div>

It’s well set up to make this easy, but we might need a `@require` or two to make it automatic. You should store your array with “rich” axis information using an `AxisArray`. JuliaImages’ `pixelspacing` trait then makes things easy.

Here’s a quick demo:

```julia
julia> using ImageAxes, AxisArrays, Unitful

julia> using Unitful: μm

julia> img = AxisArray(rand(10, 10, 4), (:y, :x, :z), (0.3μm, 0.3μm, 2μm))
3-dimensional AxisArray{Float64,3,...} with axes:
    :y, (0.0:0.3:2.7) μm
    :x, (0.0:0.3:2.7) μm
    :z, (0:2:6) μm
And data, a 10×10×4 Array{Float64,3}:
[:, :, 1] = # truncated for brevity

julia> pixelspacing(img)
(0.3 μm, 0.3 μm, 2 μm)

julia> σ = 10μm ./ pixelspacing(img)
(33.333333333333336, 33.333333333333336, 5.0)
```

---

<div class="post-metadata">

**Author:** ![mirestrepo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirestrepo/32/617_2.png) [@mirestrepo](https://discourse.julialang.org/u/mirestrepo)\
**Post date:** [June 25, 2020, 9:53pm UTC](https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/41858/4 "2020-06-25T21:53:46Z")

</div>

Thank you both for the answers. Super helpful!
