Skip to content

Commit eb63a15

Browse files
authored
deprecate the dims::Vector{Int} method of restrict (#5)
* deprecate vector dims input * update `restrict` docs * Also rename the input `region` to `dims` * format Project.toml
1 parent a6089b1 commit eb63a15

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ ImageCore = "0.8, 0.9"
1010
julia = "1"
1111

1212
[extras]
13-
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1413
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
14+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1515
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1616
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
1717

src/ImageUtils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using ImageCore.OffsetArrays
88

99
include("restrict.jl")
1010
include("compat.jl")
11+
include("deprecated.jl")
1112

1213
if VERSION >= v"1.4.2" # work around https://github.com/JuliaLang/julia/issues/34121
1314
include("precompile.jl")

src/deprecated.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# BEGIN 0.1 deprecation
2+
3+
@deprecate restrict(A::AbstractArray, region::Vector{Int}) restrict(A, (region...,))
4+
5+
# END 0.1 deprecation

src/restrict.jl

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
11
"""
2-
restrict(img[, region]) -> imgr
2+
restrict(img[, dims]) -> imgr
33
44
Reduce the size of `img` by approximately two-fold along the dimensions listed in
5-
`region`, or all spatial coordinates if `region` is not specified.
5+
`dims`, or all spatial coordinates if `dims` is not specified.
6+
7+
# Output
8+
9+
The type of output array `imgr` depends on the input type:
10+
11+
- If `img` is not an `OffsetArray`, then output array `imgr` will be a typical `Array` type.
12+
- If `img` is an `OffsetArray`, then output array `imgr` will also be an `OffsetArray`.
13+
14+
The size of `imgr` is approximately `1/2` of the original size. More specifically:
15+
16+
- if `Nₖ = size(img, k)` is odd, then `size(imgr, k) == (Nₖ+1) ÷ 2`.
17+
- if `Nₖ = size(img, k)` is even, then `size(imgr, k) == (Nₖ÷2) + 1`.
18+
19+
# Examples
20+
21+
The optional argument `dims` can be a `Tuple` or `Integer`:
22+
23+
```julia
24+
A = rand(5, 5) # size: (5, 5)
25+
26+
restrict(A) # size: (3, 3)
27+
28+
restrict(A, 1) # size: (3, 5)
29+
restrict(A, 2) # size: (5, 3)
30+
31+
restrict(A, (1, )) # size: (3, 5)
32+
restrict(A, (1, 2)) # size: (3, 3)
33+
```
34+
35+
Unless the input array is 1-based, the origin will be halfed:
36+
37+
```julia
38+
julia> using ImageUtils, OffsetArrays
39+
40+
julia> Ao = OffsetArray(rand(5, 4), 5, 6);
41+
42+
julia> Ar = restrict(Ao);
43+
44+
julia> axes(Ao)
45+
(OffsetArrays.IdOffsetRange(values=6:10, indices=6:10), OffsetArrays.IdOffsetRange(values=7:10, indices=7:10))
46+
47+
julia> axes(Ar)
48+
(OffsetArrays.IdOffsetRange(values=3:5, indices=3:5), OffsetArrays.IdOffsetRange(values=4:6, indices=4:6))
49+
```
50+
51+
# Extended help
52+
653
The term `restrict` is taken from the coarsening operation of algebraic multigrid
754
methods; it is the adjoint of "prolongation" (which is essentially interpolation).
855
`restrict` anti-aliases the image as it goes, so is better than a naive summation
@@ -69,10 +116,9 @@ In some applications (e.g., image registration), you may find it useful to trim
69116
"""
70117
restrict(img::AbstractArray, ::Tuple{}) = img
71118

72-
restrict(A::AbstractArray, region::Vector{Int}) = restrict(A, (region...,))
73119
restrict(A::AbstractArray) = restrict(A, coords_spatial(A))
74-
function restrict(A::AbstractArray, region::Dims)
75-
restrict(restrict(A, region[1]), Base.tail(region))
120+
function restrict(A::AbstractArray, dims::Dims)
121+
restrict(restrict(A, dims[1]), Base.tail(dims))
76122
end
77123

78124
function restrict(A::AbstractArray{T,N}, dim::Integer) where {T,N}

test/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@testset "deprecation" begin
2+
@testset "restrict" begin
3+
A = rand(N0f8, 4, 5, 3)
4+
@test restrict(A, [1, 2]) == restrict(A, (1, 2))
5+
end
6+
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ using Test, TestImages
33

44
@testset "ImageUtils.jl" begin
55
include("restrict.jl")
6+
7+
@info "deprecations are expected"
8+
include("deprecated.jl")
69
end

0 commit comments

Comments
 (0)