Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
TiledIteration = "06e1c1a7-607b-532d-9fad-de7d9aa2abac"

[weakdeps]
DiskArrays = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"

[extensions]
DiskArraysExt = "DiskArrays"

[compat]
DataStructures = "0.17.11, 0.18"
DiskArrays = "0.4"
Documenter = "0.24, 0.25, 0.26, 0.27"
ImageCore = "0.9, 0.10"
LoopVectorization = "0.12"
OffsetArrays = "1.9"
Requires = "1"
TiledIteration = "0.3.1, 0.4, 0.5"
julia = "1.6"
julia = "1.10"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
38 changes: 38 additions & 0 deletions ext/DiskArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module DiskArraysExt

using ImageMorphology, DiskArrays

get_extreme_value(::typeof(max), ::Type{T}) where {T} = typemin(T)
get_extreme_value(::typeof(min), ::Type{T}) where {T} = typemax(T)

function ImageMorphology.extreme_filter!(f, out, A::AbstractDiskArray, Ω)
axes(out) == axes(A) || throw(DimensionMismatch("axes(out) must match axes(A)"))
ImageMorphology.require_select_function(f, eltype(A))
val0 = get_extreme_value(f, eltype(A))

pad = extrema.(axes(Ω))
PAD1 = CartesianIndex(ntuple(i->pad[i][1], length(pad)))
PAD2 = CartesianIndex(ntuple(i->pad[i][2], length(pad)))
ZERO = CartesianIndex(ntuple(_->0, ndims(A)))
ONE = CartesianIndex(ntuple(_->1, ndims(A)))
SIZEA = CartesianIndex(size(A))
chunk_pad = [c+length(range(p...))-1
for (c,p) in zip(DiskArrays.max_chunksize(eachchunk(A)),pad)]
A_chunk = Array{eltype(A)}(undef, chunk_pad...)
out_chunk = similar(A_chunk)
for i in eachchunk(A)
I = minimum(CartesianIndices(i))
R = maximum(CartesianIndices(i))
A_chunk .= val0
A1 = max(ONE, I+PAD1)
A2 = min(SIZEA, R+PAD2)
A_chunk[ONE:A2-A1+ONE] .= A[A1:A2]
ImageMorphology._extreme_filter!(strel_type(Ω), f, out_chunk, A_chunk, Ω)
OUT1 = ONE-PAD1 + min(ZERO, I+PAD1-ONE)
OUT2 = OUT1+R-I
out[I:R] .= out_chunk[OUT1:OUT2]
end
return out
end

end
Loading