Skip to content

Commit

Permalink
Merge pull request #20 from JuliaImages/teh/widening
Browse files Browse the repository at this point in the history
Widen all-Integer eltypes. Fixes #17.
  • Loading branch information
timholy authored Jan 31, 2017
2 parents 0bbf1a3 + 09082b6 commit 5aeae13
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ julia:
notifications:
email: false
# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# For the time being, clone unregistered packages
- julia -e 'Pkg.clone("https://github.com/JuliaImages/ImageCore.jl")'
- julia -e 'Pkg.clone(pwd()); Pkg.build("ImageFiltering"); Pkg.test("ImageFiltering"; coverage=true)'
# script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("ImageFiltering"); Pkg.test("ImageFiltering"; coverage=true)'
after_success:
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("ImageFiltering")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
Expand Down
3 changes: 3 additions & 0 deletions src/imfilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ end
filter_type{S}(img::AbstractArray{S}, kernel) = filter_type(S, kernel)

filter_type{S,T}(::Type{S}, kernel::ArrayLike{T}) = typeof(zero(S)*zero(T) + zero(S)*zero(T))
filter_type{S<:Integer,T<:Integer}(::Type{S}, kernel::ArrayLike{T}) =
typeof(zero(widen(S))*zero(widen(T)) + zero(widen(S))*zero(widen(T)))
filter_type{S<:Union{Normed,FixedColorant}}(::Type{S}, ::Laplacian) = float32(S)
filter_type{S<:Colorant}(::Type{S}, kernel::Laplacian) = S
filter_type{S<:AbstractFloat}(::Type{S}, ::Laplacian) = S
Expand All @@ -982,6 +984,7 @@ filter_type(::Type{Bool}, ::Laplacian) = Int8
signed_type(::Type{UInt8}) = Int16
signed_type(::Type{UInt16}) = Int32
signed_type(::Type{UInt32}) = Int64
signed_type{T<:Integer}(::Type{T}) = Int

@inline function filter_type{S}(::Type{S}, kernel::Tuple{Any,Vararg{Any}})
T = filter_type(S, kernel[1])
Expand Down
13 changes: 13 additions & 0 deletions test/nd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ using Base.Test
@test imfilter!(r, out, img, (kern,), "replicate") == imgf
@test_throws MethodError imfilter!(r, out, img, (kern,), "replicate", Algorithm.FIR())

# Element-type widening
v = fill(0xff, 10)
kern = centered(fill(0xff, 3))
vout = imfilter(v, kern)
@test eltype(vout) == UInt32
@test all(x->x==0x0002fa03, vout)

# Cascades don't result in out-of-bounds values
k1 = centered([0.25, 0.5, 0.25])
k2 = OffsetArray([0.5, 0.5], 1:2)
Expand All @@ -62,6 +69,12 @@ using Base.Test
@test out imfilter(img, kern)
end

@testset "2d widening" begin
ret = imfilter(fill(typemax(Int16), 10, 10), centered(Int16[1 2 2 2 1])) # issue #17
@test eltype(ret) == Int32
@test all(x->x==262136, ret)
end

@testset "3d" begin
img = trues(10,10,10)
kernel = centered(trues(3,3,3)/27)
Expand Down

0 comments on commit 5aeae13

Please sign in to comment.