diff --git a/src/ImageAxes.jl b/src/ImageAxes.jl index cad4527..21636ee 100644 --- a/src/ImageAxes.jl +++ b/src/ImageAxes.jl @@ -11,6 +11,7 @@ export AxisArray, Axis, axisnames, axisvalues, axisdim, atindex, atvalue, collap @reexport using ImageCore using ImageCore.MappedArrays +using ImageCore.OffsetArrays export # types @@ -440,4 +441,7 @@ function AxisArrays._summary(io, A::AxisArray{T,N}) where {T<:Union{Fractional,C println(io, ",$N,...} with axes:") end +# glue codes +include("offsetarrays.jl") + end # module diff --git a/src/offsetarrays.jl b/src/offsetarrays.jl new file mode 100644 index 0000000..8cdc205 --- /dev/null +++ b/src/offsetarrays.jl @@ -0,0 +1,7 @@ +if isdefined(OffsetArrays, :centered) + # Requires OffsetArrays v1.9 + # https://github.com/JuliaArrays/OffsetArrays.jl/pull/242 + # Originally from ImageFiltering https://github.com/JuliaImages/ImageFiltering.jl/pull/214 + OffsetArrays.centered(ax::Axis{name}) where name = Axis{name}(OffsetArrays.centered(ax.val)) + OffsetArrays.centered(a::AxisArray) = AxisArray(OffsetArrays.centered(a.data), OffsetArrays.centered.(AxisArrays.axes(a))) +end diff --git a/test/offsetarrays.jl b/test/offsetarrays.jl new file mode 100644 index 0000000..a2dfb3c --- /dev/null +++ b/test/offsetarrays.jl @@ -0,0 +1,21 @@ +@testset "centered" begin + if isdefined(OffsetArrays, :centered) # OffsetArrays v1.9 + check_range(r, f, l) = (@test first(r) == f; @test last(r) == l) + check_range_axes(r, f, l) = check_range(Base.axes(r)[1], f, l) + + check_range(Base.axes(OffsetArrays.centered(1:3))[1], -1, 1) + a = AxisArray(rand(3, 3), Axis{:y}(0.1:0.1:0.3), Axis{:x}(1:3)) + + ca = OffsetArrays.centered(a) + axs = Base.axes(ca) + check_range(axs[1], -1, 1) + check_range(axs[2], -1, 1) + @test ca[OffsetArrays.center(ca)...] == a[OffsetArrays.center(a)...] + + axs = AxisArrays.axes(ca) + check_range(axs[1].val, 0.1, 0.3) + check_range(axs[2].val, 1, 3) + check_range_axes(axs[1].val, -1, 1) + check_range_axes(axs[1].val, -1, 1) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 0bf5135..c924fcb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using Test, ImageCore using ImageCore.MappedArrays +using ImageCore.OffsetArrays import AxisArrays ambs = detect_ambiguities(ImageCore,AxisArrays,Base,Core) @@ -232,4 +233,8 @@ end @test ImageAxes.filter_streamed((1,2), S) == (2,) end +@testset "OffsetArrays" begin + include("offsetarrays.jl") +end + nothing