Skip to content

Commit 51c608c

Browse files
authored
Merge pull request #89 from JuliaImages/teh/identityur
Fixes for various Julia versions
2 parents 3b66231 + 29a873a commit 51c608c

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

src/ImageFiltering.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Colors, FixedPointNumbers, ImageCore, MappedArrays, FFTViews, OffsetArrays
55
using Statistics, LinearAlgebra
66
using ColorVectorSpace # for filtering RGB arrays
77
using Base: Indices, tail, fill_to_length, @pure, depwarn, @propagate_inbounds
8+
using OffsetArrays: IdentityUnitRange # using the one in OffsetArrays makes this work with multiple Julia versions
89

910
export Kernel, KernelFactors, Pad, Fill, Inner, NA, NoPad, Algorithm,
1011
imfilter, imfilter!,
@@ -15,6 +16,13 @@ FixedColorant{T<:Normed} = Colorant{T}
1516
StaticOffsetArray{T,N,A<:StaticArray} = OffsetArray{T,N,A}
1617
OffsetVector{T} = OffsetArray{T,1}
1718

19+
# Add a fix that should have been included in julia-1.0.3
20+
if isdefined(Broadcast, :_sametype) && !isdefined(Broadcast, :axistype)
21+
axistype(a::T, b::T) where T = a
22+
axistype(a, b) = UnitRange{Int}(a)
23+
Broadcast._bcs1(a, b) = Broadcast._bcsm(b, a) ? axistype(b, a) : (Broadcast._bcsm(a, b) ? axistype(a, b) : throw(DimensionMismatch("arrays could not be broadcast to a common size")))
24+
end
25+
1826
# Needed for type-stability
1927
function Base.transpose(A::StaticOffsetArray{T,2}) where T
2028
inds1, inds2 = axes(A)

src/kernel.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Kernel
2020
using StaticArrays, OffsetArrays
2121
using ..ImageFiltering
2222
using ..ImageFiltering.KernelFactors
23-
import ..ImageFiltering: _reshape
23+
import ..ImageFiltering: _reshape, IdentityUnitRange
2424

2525
# We would like to do `using ..ImageFiltering.imgradients` so that that
2626
# Documenter.jl (the documentation system) can parse a reference such as `See
@@ -263,7 +263,7 @@ See also: [`KernelFactors.IIRGaussian`](@ref) and [`Kernel.Laplacian`](@ref).
263263
"""
264264
function LoG(σs::NTuple{N}) where N
265265
ws = map(n->(ceil(Int,8.5*n)>>1), σs)
266-
R = CartesianIndices(map(w->Base.Slice(-w:w), ws))
266+
R = CartesianIndices(map(w->IdentityUnitRange(-w:w), ws))
267267
σ = SVector(σs)
268268
C = 1/(prod(σ)*(2π)^(N/2))
269269
σ2 = σ.^2

test/2d.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ImageFiltering, ImageCore, OffsetArrays, Colors, FFTViews, ColorVectorSpace, ComputationalResources, FixedPointNumbers
22
using LinearAlgebra
33
using Test
4+
using ImageFiltering: IdentityUnitRange
45

56
@testset "tiling" begin
67
m = zeros(UInt8, 20, 20)
@@ -330,9 +331,11 @@ end
330331
@test r1[1,1] != r2[1,1]
331332

332333
err = ArgumentError("Fill{$Int,1}(0, (3,), (3,)) lacks the proper padding sizes for an array with 2 dimensions")
333-
@test_throws err imfilter(A, Kernel.gaussian((1,1),(3,3)), Fill(0, (3,)))
334-
err = DimensionMismatch("requested indices (1:8, 0:9) and kernel indices (Base.Slice(-1:1), Base.Slice(0:0)) do not agree with indices of padded input, (Base.Slice(0:9), Base.Slice(1:8))")
335-
@test_throws err imfilter(A, Kernel.gaussian((1,1),(3,3)), Fill(0, (1,0)))
336-
@test_throws DimensionMismatch imfilter(A, Kernel.gaussian((1,1),(3,3)), Fill(0, (0,1)))
337-
@test_throws DimensionMismatch imfilter(A, Kernel.gaussian((1,1),(3,3)), Fill(0, (0,0)))
334+
kern = Kernel.gaussian((1,1),(3,3))
335+
@test_throws err imfilter(A, kern, Fill(0, (3,)))
336+
kernf = ImageFiltering.factorkernel(kern)
337+
err = DimensionMismatch("requested indices (1:8, 0:9) and kernel indices $(axes(kernf[1])) do not agree with indices of padded input, $((IdentityUnitRange(0:9), IdentityUnitRange(1:8)))")
338+
@test_throws err imfilter(A, kern, Fill(0, (1,0)))
339+
@test_throws DimensionMismatch imfilter(A, kern, Fill(0, (0,1)))
340+
@test_throws DimensionMismatch imfilter(A, kern, Fill(0, (0,0)))
338341
end

test/mapwindow.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ImageFiltering, Statistics, Test
2+
using ImageFiltering: IdentityUnitRange
23

34
@testset "mapwindow" begin
45
function groundtruth(f, A, window::Tuple)
@@ -123,7 +124,7 @@ using ImageFiltering, Statistics, Test
123124
img_48 = 10*collect(1:10)
124125
@test mapwindow(first, img_48, (1,), border=Inner()) == img_48
125126
res_48 = mapwindow(first, img_48, (0:1,), border=Inner())
126-
@test axes(res_48) === (Base.Slice(1:9),)
127+
@test axes(res_48) === (IdentityUnitRange(1:9),)
127128
@test res_48 == img_48[axes(res_48)...]
128129
inds_48 = 2:2:8
129130
@test mapwindow(first, img_48, (0:2,),

test/specialty.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ImageFiltering, ImageCore, OffsetArrays, Colors, FixedPointNumbers
22
using Statistics, Test
3+
using ImageFiltering: IdentityUnitRange
34

45
@testset "specialty" begin
56
@testset "Laplacian" begin
@@ -164,17 +165,17 @@ using Statistics, Test
164165
for kern in (Kernel.gaussian((1.3,)), Kernel.gaussian((1.3,),(7,)))
165166
@test kern gaussiancmp(1.3, axes(kern,1))
166167
end
167-
@test KernelFactors.gaussian(2, 9) gaussiancmp(2, Base.Slice(-4:4))
168+
@test KernelFactors.gaussian(2, 9) gaussiancmp(2, IdentityUnitRange(-4:4))
168169
k = KernelFactors.gaussian((2,3), (9,7))
169-
@test vec(k[1]) gaussiancmp(2, Base.Slice(-4:4))
170-
@test vec(k[2]) gaussiancmp(3, Base.Slice(-3:3))
170+
@test vec(k[1]) gaussiancmp(2, IdentityUnitRange(-4:4))
171+
@test vec(k[2]) gaussiancmp(3, IdentityUnitRange(-3:3))
171172
@test sum(KernelFactors.gaussian(5)) 1
172173
for k = (KernelFactors.gaussian((2,3)), KernelFactors.gaussian([2,3]), KernelFactors.gaussian([2,3], [9,7]))
173174
@test sum(k[1]) 1
174175
@test sum(k[2]) 1
175176
end
176-
@test Kernel.gaussian((2,), (9,)) gaussiancmp(2, Base.Slice(-4:4))
177-
@test Kernel.gaussian((2,3), (9,7)) gaussiancmp(2, Base.Slice(-4:4)).*gaussiancmp(3, Base.Slice(-3:3))'
177+
@test Kernel.gaussian((2,), (9,)) gaussiancmp(2, IdentityUnitRange(-4:4))
178+
@test Kernel.gaussian((2,3), (9,7)) gaussiancmp(2, IdentityUnitRange(-4:4)).*gaussiancmp(3, IdentityUnitRange(-3:3))'
178179
@test sum(Kernel.gaussian(5)) 1
179180
for k = (Kernel.gaussian((2,3)), Kernel.gaussian([2,3]), Kernel.gaussian([2,3], [9,7]))
180181
@test sum(k) 1

0 commit comments

Comments
 (0)