Skip to content

Commit b4ea277

Browse files
one->oneunit for CartesianIndex (#51)
`one->oneunit` for `CartesianIndex` (for Julia <= 1.0.5) Fixes #49 Co-authored-by: Johnny Chen <[email protected]>
1 parent 49bb03c commit b4ea277

File tree

6 files changed

+13
-5
lines changed

6 files changed

+13
-5
lines changed

src/ImageSegmentation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using LinearAlgebra, Statistics
66
using Images, DataStructures, StaticArrays, ImageFiltering, LightGraphs, SimpleWeightedGraphs, RegionTrees, Distances, StaticArrays, Clustering
77
import Clustering: kmeans, fuzzy_cmeans
88

9+
include("compat.jl")
910
include("core.jl")
1011
include("region_growing.jl")
1112
include("felzenszwalb.jl")

src/compat.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if VERSION <= v"1.0.5"
2+
# https://github.com/JuliaLang/julia/pull/29442
3+
_oneunit(::CartesianIndex{N}) where {N} = _oneunit(CartesianIndex{N})
4+
_oneunit(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 1, Val(N)))
5+
else
6+
_oneunit = Base.oneunit
7+
end

src/core.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function region_adjacency_graph(s::SegmentedImage, weight_fn::Function)
8282

8383
function neighbor_regions!(n::Set{Int}, visited::AbstractArray, s::SegmentedImage, I::CartesianIndex)
8484
R = CartesianIndices(axes(s.image_indexmap))
85-
I1 = one(CartesianIndex{ndims(visited)})
85+
I1 = _oneunit(CartesianIndex{ndims(visited)})
8686
Ibegin, Iend = first(R), last(R)
8787
t = Vector{CartesianIndex{ndims(visited)}}()
8888
push!(t, I)

src/fast_scanning.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function adaptive_thres(img::AbstractArray{CT,N}, block::NTuple{N,Int}) where {C
88
net_end = last(CartesianIndices(axes(img)))
99
for i in CartesianIndices(block)
1010
si = CartesianIndex(ntuple(j->(i[j]-1)*block_length[j]+1,Val(N)))
11-
ei = min(si + block_length - one(si), net_end)
11+
ei = min(si + block_length - _oneunit(si), net_end)
1212
wi = view(img, map((i,j)->i:j, si.I, ei.I)...)
1313
threshold[i] = 0.02 + min(sharpness(wi)/net_s*0.04,0.1) + min(var(wi)/net_var*0.04,0.1)
1414
end

src/meanshift.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function meanshift(img::Array{CT, 2}, spatial_radius::Real, range_radius::Real;
4141
I1, Iend = first(R), last(R)
4242
I = CartesianIndex(rowbin(pt[1]), colbin(pt[2]), colorbin(pt[3]))
4343

44-
for J in CartesianIndices(_colon(max(I1, I-one(I)), min(Iend, I+one(I))))
44+
for J in CartesianIndices(_colon(max(I1, I-_oneunit(I)), min(Iend, I+_oneunit(I))))
4545
for point in buckets[J]
4646
if dist2(pt, SVector(point[1], point[2], img[point])) <= 1
4747
num += SVector(point[1], point[2], img[point])

src/watershed.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function watershed(img::AbstractArray{T, N},
6464
Istart, Iend = first(R), last(R)
6565
for i in R
6666
if markers[i] > 0
67-
for j in CartesianIndices(_colon(max(Istart,i-one(i)), min(i+one(i),Iend)))
67+
for j in CartesianIndices(_colon(max(Istart,i-_oneunit(i)), min(i+_oneunit(i),Iend)))
6868
if segments[j] == 0
6969
segments[j] = markers[i]
7070
enqueue!(pq, j, PK(img[i], time_step, j))
@@ -90,7 +90,7 @@ function watershed(img::AbstractArray{T, N},
9090
end
9191

9292
img_current = img[curr_idx]
93-
for j in CartesianIndices(_colon(max(Istart,curr_idx-one(curr_idx)), min(curr_idx+one(curr_idx),Iend)))
93+
for j in CartesianIndices(_colon(max(Istart,curr_idx-_oneunit(curr_idx)), min(curr_idx+_oneunit(curr_idx),Iend)))
9494

9595
# if this location is false in the mask, we skip it
9696
(!mask[j]) && continue

0 commit comments

Comments
 (0)