Skip to content

Commit

Permalink
remove clearborder (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautam98 authored Jun 29, 2020
1 parent 27f880e commit 097b212
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 119 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Images"
uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
version = "0.22.3"
version = "0.22.4"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand Down Expand Up @@ -40,7 +40,7 @@ ImageCore = "0.8.3"
ImageDistances = "0.2.5"
ImageFiltering = "0.6.3"
ImageMetadata = "0.6, 0.7, 0.8, 0.9"
ImageMorphology = "0.2.6"
ImageMorphology = "0.2.7"
ImageQualityIndexes = "0.1.3"
ImageShow = "0.1, 0.2"
ImageTransformations = "0.4, 0.5, 0.6, 0.7, 0.8"
Expand Down
1 change: 0 additions & 1 deletion src/Images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export
imROF,
otsu_threshold,
yen_threshold,
clearborder,

#Exposure
complement,
Expand Down
50 changes: 0 additions & 50 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -858,53 +858,3 @@ function yen_threshold(img::AbstractArray{T, N}, bins::Int = 256) where {T<:Unio
return T(thres)

end

"""
```
cleared_img = clearborder(img)
cleared_img = clearborder(img, width)
cleared_img = clearborder(img, width, background)
```
Returns a copy of the original image after clearing objects connected to the border of the image.
Parameters:
- img = Binary/Grayscale input image
- width = Width of the border examined (Default value is 1)
- background = Value to be given to pixels/elements that are cleared (Default value is 0)
"""
function clearborder(img::AbstractArray, width::Int=1, background::Int=0)

for i in size(img)
if(width > i)
throw(ArgumentError("Border width must not be greater than size of the image."))
end
end

connectivity = ntuple(i -> 3, ndims(img))
labels = label_components(img,trues(connectivity))
number = maximum(labels) + 1

dimensions = size(img)
outerrange = CartesianIndices(map(i -> 1:i, dimensions))
innerrange = CartesianIndices(map(i -> 1+width:i-width, dimensions))

border_labels = Set{Int64}()
for i in EdgeIterator(outerrange,innerrange)
push!(border_labels, labels[i])
end

new_img = similar(img)
for itr in eachindex(labels)
if labels[itr] in border_labels
new_img[itr] = background
else
new_img[itr] = img[itr]
end
end

return new_img

end
66 changes: 0 additions & 66 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,72 +624,6 @@ using Test
targetc = colorview(RGB, target, target, target)
@test all(map((x,y)->isapprox(x, y, atol=0.001), channelview(imROF(imgc, 0.2, 1000)), channelview(targetc)))
end

@testset "clearborder" begin
#Case when given border width is more than image size
img = [1 0 1 1 1 1
0 1 1 1 0 0
1 1 0 0 0 1
0 1 0 1 0 1
1 1 0 0 0 1
0 0 1 1 0 0]
@test_throws ArgumentError clearborder(img,7)

#Normal Case
img = [0 0 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0 0
1 0 0 1 0 1 0 0 0
0 0 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0]
cleared_img = clearborder(img)
check_img = copy(img)
check_img[3,1] = 0
check_img[1,8] = 0
@test cleared_img == check_img

cleared_img = clearborder(img,2)
@test cleared_img == fill!(similar(img), zero(eltype(img)))

cleared_img = clearborder(img,2,10)
@test cleared_img == 10*fill!(similar(img), one(eltype(img)))

#Multidimentional Case
img = cat([0 0 0 0;
0 0 0 0;
0 0 0 0;
1 0 0 0],
[0 0 0 0;
0 1 1 0;
0 0 1 0;
0 0 0 0],
[0 0 0 0;
0 0 0 0;
0 0 0 0;
0 0 0 0], dims=3)
cleared_img = clearborder(img)
check_img = copy(img)
check_img[4,1,1] = 0
@test cleared_img == check_img

cleared_img = clearborder(img,2)
@test cleared_img == fill!(similar(img), zero(eltype(img)))

cleared_img = clearborder(img,2,10)
@test cleared_img == 10*fill!(similar(img), one(eltype(img)))

#Grayscale input image Case
img = [1 2 3 1 2
3 3 5 4 2
3 4 5 4 2
3 3 2 1 2]
cleared_img = clearborder(img)
check_img = [0 0 0 0 0
0 0 5 4 0
0 4 5 4 0
0 0 0 0 0]
@test cleared_img == check_img
end
end

nothing

2 comments on commit 097b212

@johnnychen94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/17167

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.22.4 -m "<description of version>" 097b212e9bd1084c95720684e8e571f504bfc8ef
git push origin v0.22.4

Please sign in to comment.