@@ -23,46 +23,10 @@ getscalar(a::Real, i...) = a
23
23
fast_scanning (img:: AbstractArray{CT,N} , block:: NTuple{N,Int} = ntuple (i-> 4 ,Val (N))) where {CT<: ImageCore.NumberLike ,N} =
24
24
fast_scanning (img, adaptive_thres (img, block))
25
25
26
- """
27
- seg_img = fast_scanning(img, threshold, [diff_fn])
28
-
29
- Segments the N-D image using a fast scanning algorithm and returns a
30
- [`SegmentedImage`](@ref) containing information about the segments.
31
-
32
- # Arguments:
33
- * `img` : N-D image to be segmented (arbitrary axes are allowed)
34
- * `threshold` : Upper bound of the difference measure (δ) for considering
35
- pixel into same segment; an `AbstractArray` can be passed
36
- having same number of dimensions as that of `img` for adaptive
37
- thresholding
38
- * `diff_fn` : (Optional) Function that returns a difference measure (δ)
39
- between the mean color of a region and color of a point
40
-
41
- # Examples:
42
-
43
- ```jldoctest; setup = :(using ImageCore, ImageMorphology, ImageSegmentation)
44
- julia> img = zeros(Float64, (3,3));
45
-
46
- julia> img[2,:] .= 0.5;
47
-
48
- julia> img[:,2] .= 0.6;
49
-
50
- julia> seg = fast_scanning(img, 0.2);
51
-
52
- julia> labels_map(seg)
53
- 3×3 $(Matrix{Int}) :
54
- 1 4 5
55
- 4 4 4
56
- 3 4 6
57
- ```
58
-
59
- # Citation:
60
-
61
- Jian-Jiun Ding, Cheng-Jin Kuo, Wen-Chih Hong,
62
- "An efficient image segmentation technique by fast scanning and adaptive merging"
63
- """
64
- function fast_scanning (img:: AbstractArray{CT,N} , threshold:: Union{AbstractArray,Real} , diff_fn:: Function = default_diff_fn) where {CT<: Union{Colorant,Real} ,N}
26
+ fast_scanning (img:: AbstractArray{CT,N} , threshold:: Union{AbstractArray,Real} , diff_fn:: Function = default_diff_fn) where {CT<: Union{Colorant,Real} ,N} =
27
+ fast_scanning! (fill (- 1 , axes (img)), img, threshold, diff_fn)
65
28
29
+ function fast_scanning! (result, img:: AbstractArray{CT,N} , threshold:: Union{AbstractArray,Real} , diff_fn:: DF = default_diff_fn) where {CT<: Union{Colorant,Real} ,N,DF<: Function }
66
30
if threshold isa AbstractArray
67
31
ndims (img) == ndims (threshold) || error (" Dimension count of image and threshold do not match" )
68
32
end
@@ -74,7 +38,6 @@ function fast_scanning(img::AbstractArray{CT,N}, threshold::Union{AbstractArray,
74
38
75
39
# Required data structures
76
40
TM = meantype (CT)
77
- result = fill (- 1 , axes (img)) # Array to store labels
78
41
region_means = Dict {Int, TM} () # A map conatining (label, mean) pairs
79
42
region_pix_count = Dict {Int, Int} () # A map conatining (label, count) pairs
80
43
temp_labels = IntDisjointSets (0 ) # Disjoint set to map labels to their equivalence class
0 commit comments