From e5f24f6ff0d45ff7f514bfa942af23c6b655b4ba Mon Sep 17 00:00:00 2001 From: cpaniaguam Date: Wed, 6 Nov 2024 12:56:37 -0500 Subject: [PATCH 1/5] refactor: make bridge_filter generic for resue in morph_fill --- src/bridge.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 3ddaa4a59e5d348e2a84fad5b02528a62fe05162 Mon Sep 17 00:00:00 2001 From: cpaniaguam Date: Wed, 6 Nov 2024 12:56:56 -0500 Subject: [PATCH 2/5] chore: add morph_fill to module --- src/IceFloeTracker.jl | 54 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/IceFloeTracker.jl b/src/IceFloeTracker.jl index 0cc37399..58cc1ba0 100644 --- a/src/IceFloeTracker.jl +++ b/src/IceFloeTracker.jl @@ -70,7 +70,7 @@ include("branch.jl") include("special_strels.jl") include("tilingutils.jl") include("histogram_equalization.jl") - +include("morph_fill.jl") const sk_measure = PyNULL() const sk_exposure = PyNULL() @@ -152,34 +152,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 From 956054c6d14d2a7393cfc3450faf5b9286e8d21f Mon Sep 17 00:00:00 2001 From: cpaniaguam Date: Wed, 6 Nov 2024 12:57:54 -0500 Subject: [PATCH 3/5] feat: morph_fill --- src/morph_fill.jl | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/morph_fill.jl 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 From 9be0fce108907abe2ad24dfc7e273ea0e6fd299d Mon Sep 17 00:00:00 2001 From: cpaniaguam Date: Wed, 6 Nov 2024 12:58:08 -0500 Subject: [PATCH 4/5] feat: lutfill --- src/lut/lutfill.jl | 516 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 516 insertions(+) create mode 100644 src/lut/lutfill.jl 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 + 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guam Date: Wed, 6 Nov 2024 12:58:42 -0500 Subject: [PATCH 5/5] test: morph_fill --- test/test-morph-fill.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/test-morph-fill.jl 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