Skip to content

Commit 71c1c9e

Browse files
authored
Merge pull request #80 from JuliaImages/teh/fixes
Restore inadvertently deleted docstring, add NEWS.md
2 parents e18aea6 + de5cd27 commit 71c1c9e

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

NEWS.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# NEWS
2+
3+
Release 1.6:
4+
5+
- New `flood` and `flood_fill!` algorithms allow segmenting just the portion of the image connected to a seed point.
6+
- `seeded_region_growing` now allows seeds to be supplied with pair syntax, e.g.,
7+
`[CartesianIndex(300,97) => 1, CartesianIndex(145,218) => 2]`.
8+
- Kernel/window dimensions supplied in vector format are deprecated. Instead of supplying the neighborhood size as `[3,3]`, use `(3, 3)` (`seeded_region_growing` and `unseeded_region_growing`).
9+
- `felzenswalb` now supports multidimensional images.
10+
- Output types use `floattype` in more places. In some cases this has resulted in `RGB{Float32}` rather than `RGB{Float64}` outputs.

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ImageSegmentation"
22
uuid = "80713f31-8817-5129-9cf8-209ff8fb23e1"
3-
version = "1.5.1"
3+
version = "1.6.0"
44

55
[deps]
66
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"

src/core.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ accum_type(::Type{C}) where {C<:Colorant} = base_colorant_type(C){accum_type(e
77
accum_type(val) = isa(val, Type) ? throw_accum_type(val) : convert(accum_type(typeof(val)), val)
88
throw_accum_type(T) = error("type $T not supported in `accum_type`")
99

10-
_abs2(c::MathTypes) = c c
10+
# TODO:
11+
# _abs2(c::MathTypes) = c ⋅ c
12+
_abs2(c::MathTypes) = mapreducec(v->float(v)^2, +, 0, c)
1113
_abs2(x) = abs2(x)
1214

1315
default_diff_fn(c1::CT1,c2::CT2) where {CT1<:Union{Colorant,Real}, CT2<:Union{Colorant,Real}} = sqrt(_abs2(c1-accum_type(c2)))

src/fast_scanning.jl

+38
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,44 @@ getscalar(A::AbstractArray{T,N}, i::CartesianIndex{N}, block_length::CartesianIn
2020

2121
getscalar(a::Real, i...) = a
2222

23+
"""
24+
seg_img = fast_scanning(img, threshold, [diff_fn])
25+
26+
Segments the N-D image using a fast scanning algorithm and returns a
27+
[`SegmentedImage`](@ref) containing information about the segments.
28+
29+
# Arguments:
30+
* `img` : N-D image to be segmented (arbitrary axes are allowed)
31+
* `threshold` : Upper bound of the difference measure (δ) for considering
32+
pixel into same segment; an `AbstractArray` can be passed
33+
having same number of dimensions as that of `img` for adaptive
34+
thresholding
35+
* `diff_fn` : (Optional) Function that returns a difference measure (δ)
36+
between the mean color of a region and color of a point
37+
38+
# Examples:
39+
40+
```jldoctest; setup = :(using ImageCore, ImageMorphology, ImageSegmentation)
41+
julia> img = zeros(Float64, (3,3));
42+
43+
julia> img[2,:] .= 0.5;
44+
45+
julia> img[:,2] .= 0.6;
46+
47+
julia> seg = fast_scanning(img, 0.2);
48+
49+
julia> labels_map(seg)
50+
3×3 $(Matrix{Int}):
51+
1 4 5
52+
4 4 4
53+
3 4 6
54+
```
55+
56+
# Citation:
57+
58+
Jian-Jiun Ding, Cheng-Jin Kuo, Wen-Chih Hong,
59+
"An efficient image segmentation technique by fast scanning and adaptive merging"
60+
"""
2361
fast_scanning(img::AbstractArray{CT,N}, block::NTuple{N,Int} = ntuple(i->4,Val(N))) where {CT<:ImageCore.NumberLike,N} =
2462
fast_scanning(img, adaptive_thres(img, block))
2563

test/flood_fill.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ using Test
5656
# Colors
5757
path = download("https://github.com/JuliaImages/juliaimages.github.io/raw/source/docs/src/pkgs/segmentation/assets/flower.jpg")
5858
img = load(path)
59-
seg = flood(img, CartesianIndex(87,280); thresh=0.3)
59+
seg = flood(img, CartesianIndex(87,280); thresh=0.3*sqrt(3)) # TODO: eliminate the sqrt(3) when we transition to `abs2(c) = c ⋅ c`
6060
@test 0.2*length(seg) <= sum(seg) <= 0.25*length(seg)
6161
c = mean(img[seg])
6262
# N0f8 makes for easier approximate testing

0 commit comments

Comments
 (0)