Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
aquatiko committed Jan 6, 2019
1 parent 361e857 commit 77bf687
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/imfill.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 34 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 77bf687

Please sign in to comment.