JuliaImages / JuliaImages/ImageFiltering.jl

Allow unitful kernels when filtering unitful AxisArrays

Open
#176 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
104
Forks
52
PR merge metrics
No merged PRs in 30d

Description

ref. https://discourse.julialang.org/t/images-kernel-sizes-and-imageaxes/

In the following example, the kernel size is calculated based on array indices, not the provided physical dimensions of the image.

using AxisArrays, Unitful

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

An error is thrown when physical dimensions are provided for the kernel:

julia> imfilter(img, Kernel.LoG((0.25mm, 0.25mm)))
ERROR: round can only be well-defined for dimensionless numbers. For dimensionful numbers, different input units yield physically different results.
Stacktrace:
 [1] error(::String, ::String, ::String) at .\error.jl:42
 [2] _dimerr(::Symbol) at C:\Users\Alex\.julia\packages\Unitful\KE9TK\src\quantities.jl:293
 [3] round(::Type{Int64}, ::Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}, ::RoundingMode{:Up}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\Alex\.julia\packages\Unitful\KE9TK\src\quantities.jl:316
 [4] round(::Type{Int64}, ::Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}, ::RoundingMode{:Up}) at C:\Users\Alex\.julia\packages\Unitful\KE9TK\src\quantities.jl:316
 [5] ceil(::Type{Int64}, ::Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\Alex\.julia\packages\Unitful\KE9TK\src\quantities.jl:335
 [6] ceil(::Type{Int64}, ::Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}) at C:\Users\Alex\.julia\packages\Unitful\KE9TK\src\quantities.jl:335
 [7] (::ImageFiltering.Kernel.var"#3#6")(::Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}) at C:\Users\Alex\.julia\packages\ImageFiltering\eH8Od\src\kernel.jl:316
 [8] map(::ImageFiltering.Kernel.var"#3#6", ::Tuple{Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}},Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}}) at .\tuple.jl:158
 [9] LoG(::Tuple{Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}},Quantity{Float64,�,Unitful.FreeUnits{(mm,),�,nothing}}}) at C:\Users\Alex\.julia\packages\ImageFiltering\eH8Od\src\kernel.jl:316
 [10] top-level scope at REPL[39]:1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the AxisArray and Unitful example, then inspect src/kernel.jl around line 316, identified in the stack trace. Make unitful kernel sizes work with unitful axes and verify that the resulting filter uses the physical dimensions rather than only array indices.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
computer-vision
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.