Skip to content

Commit b8179fd

Browse files
authored
Merge pull request #65 from JuliaImages/teh/update0.7
Latest attempt to get this working on 0.7
2 parents 8cf536b + 87aa133 commit b8179fd

22 files changed

+419
-436
lines changed

.travis.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.6
7+
- 0.7
8+
- 1.0
89
- nightly
910
notifications:
1011
email: false
11-
# uncomment the following lines to override the default test script
12+
1213
script:
1314
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
14-
- julia -e 'Pkg.clone(pwd()); Pkg.build("ImageFiltering"); Pkg.test("ImageFiltering"; coverage=VERSION >= v"0.6.0-alpha")'
15+
- julia -e 'import Pkg; Pkg.clone(pwd()); Pkg.build("ImageFiltering")'
16+
- julia --check-bounds=yes --color=yes -e 'import Pkg; Pkg.test("ImageFiltering"; coverage=true)'
17+
# control of actual deployment is in the Documenter make script
18+
jobs:
19+
include:
20+
- stage: deploy
21+
julia: 0.7
22+
os: linux
23+
script:
24+
- julia -e 'import Pkg; Pkg.clone(pwd()); Pkg.build("ImageFiltering")'
25+
- julia -e 'import Pkg; Pkg.add("Documenter")'
26+
- julia -e 'import ImageFiltering; ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs","make.jl"))'
27+
1528
after_success:
1629
# push coverage results to Codecov
17-
- julia -e 'if VERSION >= v"0.6.0-alpha" cd(Pkg.dir("ImageFiltering")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder()); end'
18-
# update the documentation
19-
- julia -e 'Pkg.add("Documenter")'
20-
- julia -e 'cd(Pkg.dir("ImageFiltering")); ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs", "make.jl"))'
30+
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
31+

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
1+
julia 0.7
22
FixedPointNumbers 0.3.0
33
Colors
44
ColorVectorSpace
@@ -7,8 +7,8 @@ OffsetArrays
77
CatIndices
88
StaticArrays 0.0.5
99
MappedArrays
10+
FFTW 0.0.3
1011
FFTViews
1112
ComputationalResources
1213
DataStructures 0.4.6
1314
TiledIteration
14-
Compat 0.18

appveyor.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
5-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- julia_version: 0.7
4+
- julia_version: 1.0
5+
- julia_version: latest
6+
7+
platform:
8+
- x86 # 32-bit
9+
- x64 # 64-bit
710

811
branches:
912
only:
@@ -17,19 +20,12 @@ notifications:
1720
on_build_status_changed: false
1821

1922
install:
20-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
21-
# Download most recent Julia Windows binary
22-
- ps: (new-object net.webclient).DownloadFile(
23-
$env:JULIA_URL,
24-
"C:\projects\julia-binary.exe")
25-
# Run installer silently, output to C:\projects\julia
26-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
23+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
2724

2825
build_script:
29-
# Need to convert from shallow to complete for Pkg.clone to work
30-
- IF EXIST .git\shallow (git fetch --unshallow)
31-
- C:\projects\julia\bin\julia -e "versioninfo();
32-
Pkg.clone(pwd(), \"ImageFiltering\"); Pkg.build(\"ImageFiltering\")"
26+
- echo "%JL_BUILD_SCRIPT%"
27+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
3328

3429
test_script:
35-
- C:\projects\julia\bin\julia -e "Pkg.test(\"ImageFiltering\")"
30+
- echo "%JL_TEST_SCRIPT%"
31+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

src/ImageFiltering.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
__precompile__()
2-
31
module ImageFiltering
42

3+
using FFTW
54
using Colors, FixedPointNumbers, ImageCore, MappedArrays, FFTViews, OffsetArrays, StaticArrays, ComputationalResources, TiledIteration
5+
using Statistics, LinearAlgebra
66
using ColorVectorSpace # for filtering RGB arrays
7-
using Compat
8-
using Base: Indices, tail, fill_to_length, @pure, depwarn
7+
using Base: Indices, tail, fill_to_length, @pure, depwarn, @propagate_inbounds
98

109
export Kernel, KernelFactors, Pad, Fill, Inner, NA, NoPad, Algorithm,
1110
imfilter, imfilter!,
@@ -18,14 +17,13 @@ OffsetVector{T} = OffsetArray{T,1}
1817

1918
# Needed for type-stability
2019
function Base.transpose(A::StaticOffsetArray{T,2}) where T
21-
inds1, inds2 = indices(A)
20+
inds1, inds2 = axes(A)
2221
OffsetArray(transpose(parent(A)), inds2, inds1)
2322
end
2423

2524
module Algorithm
2625
# deliberately don't export these, but it's expected that they
2726
# will be used as Algorithm.FFT(), etc.
28-
using Compat
2927
abstract type Alg end
3028
"Filter using the Fast Fourier Transform" struct FFT <: Alg end
3129
"Filter using a direct algorithm" struct FIR <: Alg end

src/border.jl

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ end
130130

131131

132132
Pad{N}(style, lo::AbstractVector, hi::AbstractVector) where {N} =
133-
Pad{N}(style, (lo...), (hi...))
133+
Pad{N}(style, (lo...,), (hi...,))
134134

135135
const valid_borders = ("replicate", "circular", "reflect", "symmetric")
136136

@@ -200,8 +200,8 @@ should be replicated by three and four pixels.
200200
"""
201201
Pad(lo::Dims, hi::Dims) = Pad(:replicate, lo, hi)
202202
Pad(style::Symbol, lo::Tuple{}, hi::Tuple{}) = Pad{0}(style, lo, hi)
203-
Pad(style::Symbol, lo::Dims{N}, hi::Tuple{}) where {N} = Pad(style, lo, ntuple(d->0,Val{N}))
204-
Pad(style::Symbol, lo::Tuple{}, hi::Dims{N}) where {N} = Pad(style, ntuple(d->0,Val{N}), hi)
203+
Pad(style::Symbol, lo::Dims{N}, hi::Tuple{}) where {N} = Pad(style, lo, ntuple(d->0,Val(N)))
204+
Pad(style::Symbol, lo::Tuple{}, hi::Dims{N}) where {N} = Pad(style, ntuple(d->0,Val(N)), hi)
205205
Pad(style::Symbol, lo::AbstractVector{Int}, hi::AbstractVector{Int}) = Pad(style, (lo...,), (hi...,))
206206

207207
Pad(style::Symbol, inds::Indices) = Pad(style, map(lo,inds), map(hi,inds))
@@ -211,7 +211,7 @@ Pad(style::Symbol, inds::Indices) = Pad(style, map(lo,inds), map(hi,inds))
211211
Pad(style, kernel)
212212
Pad(style)(kernel)
213213
```
214-
Construct an instance of [`Pad`](@ref) by designating the value `val` and a filter array `kernel` which will be used to determine the amount of padding from the `indices` of `kernel`.
214+
Construct an instance of [`Pad`](@ref) by designating the value `val` and a filter array `kernel` which will be used to determine the amount of padding from the `axes` of `kernel`.
215215
216216
#### Usage illustration
217217
@@ -228,19 +228,19 @@ the minimal amount of padding necessary to ensure that convolution with
228228
# Padding for FFT: round up to next size expressible as 2^m*3^n
229229
function (p::Pad{0})(kernel, img, ::FFT)
230230
inds = calculate_padding(kernel)
231-
newinds = map(padfft, inds, map(length, indices(img)))
231+
newinds = map(padfft, inds, map(length, axes(img)))
232232
Pad(p.style, newinds)
233233
end
234234
function padfft(indk::AbstractUnitRange, l::Integer)
235235
lk = length(indk)
236-
range(first(indk), nextprod([2,3], l+lk)-l+1)
236+
range(first(indk), length=nextprod([2,3], l+lk)-l+1)
237237
end
238238

239239
function padindices(img::AbstractArray{_,N}, border::Pad) where {_,N}
240240
throw(ArgumentError("$border lacks the proper padding sizes for an array with $(ndims(img)) dimensions"))
241241
end
242242
function padindices(img::AbstractArray{_,N}, border::Pad{N}) where {_,N}
243-
_padindices(border, border.lo, indices(img), border.hi)
243+
_padindices(border, border.lo, axes(img), border.hi)
244244
end
245245
function padindices(img::AbstractArray, ::Type{P}) where P<:Pad
246246
throw(ArgumentError("must supply padding sizes to $P"))
@@ -656,7 +656,7 @@ padarray(img::AbstractArray, border::Pad) = padarray(eltype(img), img, border)
656656
function padarray(::Type{T}, img::AbstractArray, border::Pad) where T
657657
inds = padindices(img, border)
658658
# like img[inds...] except that we can control the element type
659-
newinds = map(Base.indices1, inds)
659+
newinds = map(Base.axes1, inds)
660660
dest = similar(img, T, newinds)
661661
copydata!(dest, img, inds)
662662
end
@@ -665,12 +665,12 @@ padarray(img, ::Type{P}) where {P} = img[padindices(img, P)...] # just to t
665665

666666
function copydata!(dest, img, inds)
667667
isempty(inds) && return dest
668-
idest = indices(dest)
668+
idest = axes(dest)
669669
# Work around julia #9080
670670
i1, itail = idest[1], tail(idest)
671671
inds1, indstail = inds[1], tail(inds)
672-
@unsafe for I in CartesianRange(itail)
673-
J = CartesianIndex(map((i,x)->x[i], I.I, indstail))
672+
@inbounds for I in CartesianIndices(itail)
673+
J = CartesianIndex(map((i,x)->x[i], Tuple(I), indstail))
674674
for i in i1
675675
j = inds1[i]
676676
dest[i,I] = img[j,J]
@@ -726,14 +726,14 @@ end
726726

727727
for T in (:Inner, :NA)
728728
@eval begin
729-
(::Type{$T})(both::Int...) = $T(both, both)
730-
(::Type{$T})(both::Dims{N}) where {N} = $T(both, both)
731-
(::Type{$T})(lo::Tuple{}, hi::Tuple{}) = $T{0}(lo, hi)
732-
(::Type{$T})(lo::Dims{N}, hi::Tuple{}) where {N} = $T{N}(lo, ntuple(d->0,Val{N}))
733-
(::Type{$T})(lo::Tuple{}, hi::Dims{N}) where {N} = $T{N}(ntuple(d->0,Val{N}), hi)
734-
(::Type{$T})(inds::Indices{N}) where {N} = $T{N}(map(lo,inds), map(hi,inds))
735-
(::Type{$T{N}})(lo::AbstractVector, hi::AbstractVector) where {N} = $T{N}((lo...,), (hi...,))
736-
(::Type{$T})(lo::AbstractVector, hi::AbstractVector) = $T((lo...,), (hi...,)) # not inferrable
729+
$T(both::Int...) = $T(both, both)
730+
$T(both::Dims{N}) where {N} = $T(both, both)
731+
$T(lo::Tuple{}, hi::Tuple{}) = $T{0}(lo, hi)
732+
$T(lo::Dims{N}, hi::Tuple{}) where {N} = $T{N}(lo, ntuple(d->0,Val(N)))
733+
$T(lo::Tuple{}, hi::Dims{N}) where {N} = $T{N}(ntuple(d->0,Val(N)), hi)
734+
$T(inds::Indices{N}) where {N} = $T{N}(map(lo,inds), map(hi,inds))
735+
$T{N}(lo::AbstractVector, hi::AbstractVector) where {N} = $T{N}((lo...,), (hi...,))
736+
$T(lo::AbstractVector, hi::AbstractVector) = $T((lo...,), (hi...,)) # not inferrable
737737

738738
(p::$T{0})(kernel, img, ::Alg) = p(kernel)
739739
(p::$T{0})(kernel) = $T(calculate_padding(kernel))
@@ -742,7 +742,7 @@ end
742742

743743
padarray(img, border::Inner) = padarray(eltype(img), img, border)
744744
padarray(::Type{T}, img::AbstractArray{T}, border::Inner) where {T} = copy(img)
745-
padarray(::Type{T}, img::AbstractArray, border::Inner) where {T} = copy!(similar(Array{T}, indices(img)), img)
745+
padarray(::Type{T}, img::AbstractArray, border::Inner) where {T} = copyto!(similar(Array{T}, axes(img)), img)
746746

747747
"""
748748
```julia
@@ -888,26 +888,22 @@ Fill(value, kernel) = Fill(value, calculate_padding(kernel))
888888
(p::Fill)(kernel, img, ::Alg) = Fill(p.value, kernel)
889889
function (p::Fill)(kernel, img, ::FFT)
890890
inds = calculate_padding(kernel)
891-
newinds = map(padfft, inds, map(length, indices(img)))
891+
newinds = map(padfft, inds, map(length, axes(img)))
892892
Fill(p.value, newinds)
893893
end
894894

895895
function padarray(::Type{T}, img::AbstractArray, border::Fill) where T
896896
throw(ArgumentError("$border lacks the proper padding sizes for an array with $(ndims(img)) dimensions"))
897897
end
898898
function padarray(::Type{T}, img::AbstractArray{S,N}, f::Fill{_,N}) where {T,S,_,N}
899-
A = similar(arraytype(img, T), map((l,r,h)->first(r)-l:last(r)+h, f.lo, indices(img), f.hi))
899+
paxs = map((l,r,h)->first(r)-l:last(r)+h, f.lo, axes(img), f.hi)
900+
A = similar(arraytype(img, T), paxs)
900901
try
901902
fill!(A, f.value)
902903
catch
903904
error("Unable to fill! an array of element type $(eltype(A)) with the value $(f.value). Supply an appropriate value to `Fill`, such as `zero(eltype(A))`.")
904905
end
905-
906-
# We would have liked to do A[indices(img)...] = img, but this calls size(img)
907-
# which is not defined if img is of type OffsetArrays.
908-
for I in Compat.CartesianIndices(Compat.axes(img))
909-
A[I] = img[I]
910-
end
906+
A[axes(img)...] = img
911907
A
912908
end
913909
padarray(img::AbstractArray, f::Fill) = padarray(eltype(img), img, f)
@@ -917,21 +913,21 @@ padarray(img::AbstractArray, f::Fill) = padarray(eltype(img), img, f)
917913
"""
918914
padindex(border::Pad, lo::Integer, inds::AbstractUnitRange, hi::Integer)
919915
920-
Generate an index-vector to be used for padding. `inds` specifies the image indices along a particular axis; `lo` and `hi` are the amount to pad on the lower and upper, respectively, sides of this axis. `border` specifying the style of padding.
916+
Generate an index-vector to be used for padding. `inds` specifies the image axes along a particular axis; `lo` and `hi` are the amount to pad on the lower and upper, respectively, sides of this axis. `border` specifying the style of padding.
921917
"""
922918
function padindex(border::Pad, lo::Integer, inds::AbstractUnitRange, hi::Integer)
923919
if border.style == :replicate
924-
indsnew = vcat(fill(first(inds), lo), inds, fill(last(inds), hi))
920+
indsnew = vcat(fill(first(inds), lo), UnitRange(inds), fill(last(inds), hi))
925921
OffsetArray(indsnew, first(inds)-lo:last(inds)+hi)
926922
elseif border.style == :circular
927923
return modrange(extend(lo, inds, hi), inds)
928924
elseif border.style == :symmetric
929-
I = OffsetArray([inds; reverse(inds)], (0:2*length(inds)-1)+first(inds))
930-
r = modrange(extend(lo, inds, hi), indices(I, 1))
925+
I = OffsetArray([inds; reverse(inds)], (0:2*length(inds)-1) .+ first(inds))
926+
r = modrange(extend(lo, inds, hi), axes(I, 1))
931927
return I[r]
932928
elseif border.style == :reflect
933-
I = OffsetArray([inds; last(inds)-1:-1:first(inds)+1], (0:2*length(inds)-3)+first(inds))
934-
return I[modrange(extend(lo, inds, hi), indices(I, 1))]
929+
I = OffsetArray([inds; last(inds)-1:-1:first(inds)+1], (0:2*length(inds)-3) .+ first(inds))
930+
return I[modrange(extend(lo, inds, hi), axes(I, 1))]
935931
else
936932
error("border style $(border.style) unrecognized")
937933
end
@@ -958,9 +954,9 @@ function extend(lo::Integer, inds::AbstractUnitRange, hi::Integer)
958954
OffsetArray(newind, newind)
959955
end
960956

961-
calculate_padding(kernel) = indices(kernel)
957+
calculate_padding(kernel) = axes(kernel)
962958
@inline function calculate_padding(kernel::Tuple{Any, Vararg{Any}})
963-
inds = accumulate_padding(indices(kernel[1]), tail(kernel)...)
959+
inds = accumulate_padding(axes(kernel[1]), tail(kernel)...)
964960
if hasiir(kernel) && hasfir(kernel)
965961
inds = map(doublepadding, inds)
966962
end
@@ -985,7 +981,7 @@ function doublepadding(ind::AbstractUnitRange)
985981
end
986982

987983
accumulate_padding(inds::Indices, kernel1, kernels...) =
988-
accumulate_padding(expand(inds, indices(kernel1)), kernels...)
984+
accumulate_padding(expand(inds, axes(kernel1)), kernels...)
989985
accumulate_padding(inds::Indices) = inds
990986

991987
modrange(x, r::AbstractUnitRange) = mod(x-first(r), length(r))+first(r)
@@ -994,10 +990,10 @@ modrange(A::AbstractArray, r::AbstractUnitRange) = map(x->modrange(x, r), A)
994990
arraytype(A::AbstractArray, ::Type{T}) where {T} = Array{T} # fallback
995991
arraytype(A::BitArray, ::Type{Bool}) = BitArray
996992

997-
interior(A, kernel) = _interior(indices(A), indices(kernel))
998-
interior(A, factkernel::Tuple) = _interior(indices(A), accumulate_padding(indices(factkernel[1]), tail(factkernel)...))
993+
interior(A, kernel) = _interior(axes(A), axes(kernel))
994+
interior(A, factkernel::Tuple) = _interior(axes(A), accumulate_padding(axes(factkernel[1]), tail(factkernel)...))
999995
function _interior(indsA::NTuple{N}, indsk) where N
1000-
indskN = fill_to_length(indsk, 0:0, Val{N})
996+
indskN = fill_to_length(indsk, 0:0, Val(N))
1001997
map(intersect, indsA, shrink(indsA, indsk))
1002998
end
1003999

0 commit comments

Comments
 (0)