Skip to content

Commit 5b9e420

Browse files
authored
Rename rem_segment -> remove_segment (#47)
Also remove outdated code
1 parent c93ce87 commit 5b9e420

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

src/ImageSegmentation.jl

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

9-
# For efficient hashing of CartesianIndex
10-
if !isdefined(Base.IteratorsMD, :cartindexhash_seed)
11-
const cartindexhash_seed = UInt == UInt64 ? 0xd60ca92f8284b8b0 : 0xf2ea7c2e
12-
function Base.hash(ci::CartesianIndex, h::UInt)
13-
h += cartindexhash_seed
14-
for i in ci.I
15-
h = hash(i, h)
16-
end
17-
return h
18-
end
19-
end
20-
219
include("core.jl")
2210
include("region_growing.jl")
2311
include("felzenszwalb.jl")
@@ -42,8 +30,8 @@ export
4230
watershed,
4331
hmin_transform,
4432
region_adjacency_graph,
45-
rem_segment,
46-
rem_segment!,
33+
remove_segment,
34+
remove_segment!,
4735
prune_segments,
4836
region_tree,
4937
region_splitting,
@@ -55,4 +43,7 @@ export
5543
SegmentedImage,
5644
ImageEdge
5745

46+
@deprecate rem_segment remove_segment
47+
@deprecate rem_segment! remove_segment!
48+
5849
end # module

src/core.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ end
128128

129129

130130
"""
131-
new_seg = rem_segment(seg, label, diff_fn)
131+
new_seg = remove_segment(seg, label, diff_fn)
132132
133133
Removes the segment having label `label` and returns the new `SegmentedImage`.
134134
For more info, see [`remove_segment!`](@ref)
135135
136136
"""
137-
rem_segment(s::SegmentedImage, args...) = rem_segment!(deepcopy(s), args...)
137+
remove_segment(s::SegmentedImage, args...) = remove_segment!(deepcopy(s), args...)
138138

139139
"""
140-
rem_segment!(seg, label, diff_fn)
140+
remove_segment!(seg, label, diff_fn)
141141
142142
In place removal of the segment having label `label`, replacing it with the neighboring
143143
segment having least `diff_fn` value.
@@ -152,15 +152,15 @@ defined for objects of the type of `d`.
152152
```julia
153153
# This removes the label `l` and replaces it with the label of
154154
# neighbor having maximum pixel count.
155-
julia> rem_segment!(seg, l, (i,j)->(-seg.segment_pixel_count[j]))
155+
julia> remove_segment!(seg, l, (i,j)->(-seg.segment_pixel_count[j]))
156156
157157
# This removes the label `l` and replaces it with the label of
158158
# neighbor having the least value of euclidian metric.
159-
julia> rem_segment!(seg, l, (i,j)->sum(abs2, seg.segment_means[i]-seg.segment_means[j]))
159+
julia> remove_segment!(seg, l, (i,j)->sum(abs2, seg.segment_means[i]-seg.segment_means[j]))
160160
```
161161
162162
"""
163-
function rem_segment!(s::SegmentedImage, label::Int, diff_fn::Function)
163+
function remove_segment!(s::SegmentedImage, label::Int, diff_fn::Function)
164164
haskey(s.segment_means, label) || error("Label $label not present!")
165165
G, vert_map = region_adjacency_graph(s, (i,j)->1)
166166
vert_label = vert_map[label]
@@ -275,9 +275,9 @@ with a mapping from vertex index in RAG to cartesian index in the image.
275275
`weight_fn` is used to assign weights to the edges using pixel similarity and spatial proximity,
276276
where higher weight means greater similarity and thus stronger association. Zero weight is assigned
277277
to edges between any pair of nodes that are more than `R` pixels apart. `R` can be specified
278-
as a N-dimensional `CartesianIndex`. Alternatively, `R` can be an integer, in which a
278+
as a N-dimensional `CartesianIndex`. Alternatively, `R` can be an integer, in which a
279279
N-dimensional `CartesianIndex` with value `R` along each dimension is used. `weight_fn` should have
280-
signature -
280+
signature -
281281
282282
edge_weight = weight_fn(p1::Pair{CartesianIndex{N},T}, p2::Pair{CartesianIndex{N},T}) where {N,T}
283283
@@ -308,7 +308,7 @@ function region_adjacency_graph(img::AbstractArray{CT,N}, weight_fn::Function, R
308308
Istart, Iend = first(indices), last(indices)
309309
for I in indices
310310
for J in CartesianIndices(map((i,j)->i:j, Tuple(max(Istart, I-R)), Tuple(min(Iend, I+R))))
311-
if I <= J
311+
if I <= J
312312
continue
313313
end
314314
push!(sources, cartesian2vertex[I])

test/core.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
@test g == expectedg
5050
@test vm == expectedvm
5151

52-
# rem_segment
52+
# remove_segment
5353
img = fill(1.0, (10,10))
5454
img[1:4,:] .= 2.0
5555
img[:,5:10] .= 4.0
5656
seg = fast_scanning(img, 0.5)
57-
new_seg = rem_segment(seg, 1, (i,j)->(-seg.segment_pixel_count[j]))
57+
new_seg = remove_segment(seg, 1, (i,j)->(-seg.segment_pixel_count[j]))
5858

5959
expected = fill(3, (10,10))
6060
expected[5:10,1:4] .= 2
@@ -68,7 +68,7 @@
6868
@test all(label->(expected_means[label] new_seg.segment_means[label]), new_seg.segment_labels)
6969
@test new_seg.image_indexmap == expected
7070

71-
new_seg = rem_segment(seg, 1, (i,j)->sum(abs2, seg.segment_means[i]-seg.segment_means[j]))
71+
new_seg = remove_segment(seg, 1, (i,j)->sum(abs2, seg.segment_means[i]-seg.segment_means[j]))
7272

7373
expected = fill(3, (10,10))
7474
expected[:,1:4] .= 2
@@ -81,7 +81,7 @@
8181
@test all(label->(expected_means[label] new_seg.segment_means[label]), new_seg.segment_labels)
8282
@test new_seg.image_indexmap == expected
8383

84-
rem_segment!(seg, 1, (i,j)->sum(abs2, seg.segment_means[i]-seg.segment_means[j]))
84+
remove_segment!(seg, 1, (i,j)->sum(abs2, seg.segment_means[i]-seg.segment_means[j]))
8585

8686
@test all(label->(label in expected_labels), seg.segment_labels)
8787
@test all(label->(label in seg.segment_labels), expected_labels)

0 commit comments

Comments
 (0)