diff --git a/src/IceFloeTracker.jl b/src/IceFloeTracker.jl index 4628609b..5ce395cf 100644 --- a/src/IceFloeTracker.jl +++ b/src/IceFloeTracker.jl @@ -71,9 +71,9 @@ include("branch.jl") include("special_strels.jl") include("tilingutils.jl") include("histogram_equalization.jl") +include("morph_fill.jl") include("imcomplement.jl") - const sk_measure = PyNULL() const sk_exposure = PyNULL() const getlatlon = PyNULL() @@ -154,34 +154,34 @@ julia> IceFloeTracker.MorphSE.dilate(a, se) ``` """ module MorphSE -using ImageCore -using ColorTypes -using LoopVectorization -using OffsetArrays -using TiledIteration: EdgeIterator -using DataStructures -include("morphSE/StructuringElements.jl") -using .StructuringElements -include("morphSE/extreme_filter.jl") -include("morphSE/utils.jl") -include("morphSE/dilate.jl") -include("morphSE/erode.jl") -include("morphSE/opening.jl") -include("morphSE/closing.jl") -include("morphSE/bothat.jl") -include("morphSE/mreconstruct.jl") -include("morphSE/fill_holes.jl") + using ImageCore + using ColorTypes + using LoopVectorization + using OffsetArrays + using TiledIteration: EdgeIterator + using DataStructures + include("morphSE/StructuringElements.jl") + using .StructuringElements + include("morphSE/extreme_filter.jl") + include("morphSE/utils.jl") + include("morphSE/dilate.jl") + include("morphSE/erode.jl") + include("morphSE/opening.jl") + include("morphSE/closing.jl") + include("morphSE/bothat.jl") + include("morphSE/mreconstruct.jl") + include("morphSE/fill_holes.jl") end module Register -include("Register/CenterIndexedArrays.jl-0.2.0/CenterIndexedArrays.jl") -include("Register/RegisterCore.jl-0.2.4/src/RegisterCore.jl") -include("Register/RegisterMismatchCommon.jl-master/RegisterMismatchCommon.jl") -include("Register/RegisterUtilities.jl-master/RegisterUtilities.jl") -include("Register/RFFT.jl-master/RFFT.jl") -include("Register/RegisterDeformation.jl-0.4.4/RegisterDeformation.jl") -include("Register/QuadDIRECT.jl-master/QuadDIRECT.jl") -include("Register/RegisterQD.jl-0.3.1/RegisterQD.jl") -include("Register/RegisterMismatch.jl-0.4.0/RegisterMismatch.jl") + include("Register/CenterIndexedArrays.jl-0.2.0/CenterIndexedArrays.jl") + include("Register/RegisterCore.jl-0.2.4/src/RegisterCore.jl") + include("Register/RegisterMismatchCommon.jl-master/RegisterMismatchCommon.jl") + include("Register/RegisterUtilities.jl-master/RegisterUtilities.jl") + include("Register/RFFT.jl-master/RFFT.jl") + include("Register/RegisterDeformation.jl-0.4.4/RegisterDeformation.jl") + include("Register/QuadDIRECT.jl-master/QuadDIRECT.jl") + include("Register/RegisterQD.jl-0.3.1/RegisterQD.jl") + include("Register/RegisterMismatch.jl-0.4.0/RegisterMismatch.jl") end end diff --git a/src/bridge.jl b/src/bridge.jl index ed973b98..997225cb 100644 --- a/src/bridge.jl +++ b/src/bridge.jl @@ -9,7 +9,8 @@ function _bridge_operator_lut( return _operator_lut(I, img, nhood, lutbridge) end -function _bridge_filter(img::T, operator::Function)::T where {T<:AbstractArray{Bool}} +# TODO: see about implemting _filter using parallelization +function _filter(img::T, operator::Function)::T where {T<:AbstractArray{Bool}} out = zeros(Bool, size(img)) R = CartesianIndices(img) I_first, I_last = first(R), last(R) @@ -79,5 +80,5 @@ julia> bridge(bw) ``` """ function bridge(bw::T)::T where {T<:AbstractArray{Bool}} - return _bridge_filter(bw, _bridge_operator_lut) + return _filter(bw, _bridge_operator_lut) end diff --git a/src/lut/lutfill.jl b/src/lut/lutfill.jl new file mode 100644 index 00000000..12e31588 --- /dev/null +++ b/src/lut/lutfill.jl @@ -0,0 +1,516 @@ +function make_lutfill() + return [ + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 +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 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + ] +end diff --git a/src/morph_fill.jl b/src/morph_fill.jl new file mode 100644 index 00000000..5403b803 --- /dev/null +++ b/src/morph_fill.jl @@ -0,0 +1,38 @@ +include("./lut/lutfill.jl") + +function _fill_operator_lut( + I::CartesianIndex{2}, + img::AbstractArray{Bool}, + nhood::CartesianIndices{2,Tuple{UnitRange{Int64},UnitRange{Int64}}}, +) + return _operator_lut(I, img, nhood, make_lutfill()) +end + +""" + morph_fill(bw::T)::T where {T<:AbstractArray{Bool}} + +Fill holes in binary image `bw` by setting 0-valued pixels to 1 if they are surrounded by 1-valued pixels. + +# Examples + +```jldoctest; setup = :(using IceFloeTracker) +julia> bw = Bool[ + 0 0 0 0 0 + 0 1 1 1 0 + 0 1 0 1 0 + 0 1 1 1 0 + 0 0 0 0 0 + ]; + +julia> morph_fill(bw) +5×5 Matrix{Bool}: + 0 0 0 0 0 + 0 1 1 1 0 + 0 1 1 1 0 + 0 1 1 1 0 + 0 0 0 0 0 +""" +function morph_fill(bw::T)::T where {T<:AbstractArray{Bool}} + # TODO: see about implemting _filter using parallelization + return _filter(bw, _fill_operator_lut) +end diff --git a/test/test-morph-fill.jl b/test/test-morph-fill.jl new file mode 100644 index 00000000..26ba7b00 --- /dev/null +++ b/test/test-morph-fill.jl @@ -0,0 +1,21 @@ +using IceFloeTracker: morph_fill + +@testset "morp_fill.jl" begin + println("------------------------------------------------") + println("----------- Create Morp Fill Test --------------") + + img = Bool[ + 0 0 0 0 0 + 0 1 1 1 0 + 0 1 0 1 0 + 0 1 1 1 0 + 0 0 0 0 0 + ] + + r = rand(1:100) + + imgbig = repeat(img, r, r) + + filled = morph_fill(imgbig) + @test sum(filled) - sum(imgbig) == r^2 +end