Skip to content

Commit

Permalink
Fix mapwindow for offset arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
yha committed May 25, 2020
1 parent 8c9f173 commit 77cb511
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/mapwindow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ function _indices_of_interiour_range(
idx1 = _intersectionindices(fullimgr, kmin .+ imgr)
idx2 = _intersectionindices(fullimgr, kmax .+ imgr)
idx = intersect(idx1, idx2)
@assert imgr[idx] .+ kmin fullimgr
@assert imgr[idx] .+ kmax fullimgr
idx
end

function _indices_of_interiour_indices(fullimginds, imginds, kerinds)
Expand Down Expand Up @@ -375,7 +372,7 @@ extrema_filter(A::AbstractArray, window) = error("`window` must have the same nu

extrema_filter(A::AbstractArray{T,N}, window::Integer) where {T,N} = extrema_filter(A, ntuple(d->window, Val{N}))

function _extrema_filter!(A::Array, w1, w...)
function _extrema_filter!(A::AbstractArray, w1, w...)
if w1 > 1
a = first(A)
if w1 <= 20
Expand All @@ -396,7 +393,7 @@ function _extrema_filter!(A::Array, w1, w...)
return A
end
end
_extrema_filter!(A::Array) = A
_extrema_filter!(A::AbstractArray) = A

# Extrema-filtering along "columns" (dimension 1). This implements Lemire
# Algorithm 1, with the following modifications:
Expand Down
14 changes: 14 additions & 0 deletions test/mapwindow.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ImageFiltering, Statistics, Test
using ImageFiltering: IdentityUnitRange
using OffsetArrays

@testset "mapwindow" begin
function groundtruth(f, A, window::Tuple)
Expand Down Expand Up @@ -71,6 +72,19 @@ using ImageFiltering: IdentityUnitRange
Amin = groundtruth(min, A, w)
@test minval == Amin
end
# offsets
@testset "offsets" begin
arrays = [rand(5), rand(5,5), rand(5,5,5)]
@testset "offsets ($f, $offset, $window, $dim)" for f in (extrema,maximum,minimum),
offset in -5:5,
window in [1:2:9; [0:2,-2:0]],
(dim,a) in enumerate(arrays)
offsets = ntuple(_->offset,dim)
windows = ntuple(_->window,dim)
@test OffsetArray(mapwindow(f,a,windows),offsets) == mapwindow(f,OffsetArray(a,offsets),windows)
end
end


# median
for f in (median, median!)
Expand Down

0 comments on commit 77cb511

Please sign in to comment.