Images - Kernel sizes and ImageAxes

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!

Image filtering doesn’t take axis sizing into account:

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

1 Like

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> 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)
2 Likes

Thank you both for the answers. Super helpful!

1 Like