diff --git a/src/imfill.jl b/src/imfill.jl index c137f6a7..89a70435 100644 --- a/src/imfill.jl +++ b/src/imfill.jl @@ -9,17 +9,23 @@ Connected components of an image is found using flood-fill algorithm and returns a copy of the original image after filling objects that falls in the range of interval. + For filling objects, represent the holes(part to be filled) with True in your array. Parameters: - img = Input image (Boolean array type) - - interval = objects of size in this range will be filled with False (default value is (0,64) ) + - interval = objects of size in this range will be filled with False - connectivity = connectivity takes the same values as in label_components (Default value is 1:ndims(img)) """ - function imfill(img::AbstractArray{Bool}, interval::Tuple{Real,Real}=(0,64), connectivity::Union{Dims, AbstractVector{Int}, BitArray}=1:ndims(img)) + function imfill(img::AbstractArray{Bool}, interval::Tuple{Real,Real}, connectivity::Union{Dims, AbstractVector{Int}, BitArray}=1:ndims(img)) + + if interval[1] > interval[2] || interval[1] < 0 || interval[2] < 0 + print("Invalid Interval") + return + end labels = label_components(img,connectivity) diff --git a/test/runtests.jl b/test/runtests.jl index 1fe2d75b..60ce8a30 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -135,4 +135,38 @@ using Test 0 0 0 0 0 0]) @test thinning(img) == img end + + @testset "imfill" begin + #2 Dimensional case + img = Bool.([0 0 0 0 0 0 1 0 0 0 + 0 1 1 1 1 1 0 0 0 0 + 0 1 0 0 1 1 0 0 0 0 + 0 1 1 1 0 1 0 0 0 0 + 0 1 1 1 1 1 0 0 0 0 + 0 0 0 0 0 0 0 1 1 1 + 0 0 0 0 0 0 0 1 0 1 + 0 0 0 0 0 0 0 1 1 1]) + ans = Bool.([0 0 0 0 0 0 1 0 0 0 + 0 1 1 1 1 1 0 0 0 0 + 0 1 1 1 1 1 0 0 0 0 + 0 1 1 1 1 1 0 0 0 0 + 0 1 1 1 1 1 0 0 0 0 + 0 0 0 0 0 0 0 1 1 1 + 0 0 0 0 0 0 0 1 1 1 + 0 0 0 0 0 0 0 1 1 1]) + @test imfill(.!img, (0,2)) == (.!ans) + + #3 Dimensional case + A = zeros(Bool,3,10,10) + A[1,:,:] = img + A[2,:,:] = img + A[3,:,:] = img + + B = zeros(Bool,3,10,10) + B[1,:,:] = ans + B[2,:,:] = ans + B[3,:,:] = ans + + @test imfill(.!A, (0,2)) == (.!B) + end end