Open
Description
using Images: realtype
function ifi{T<:Real,K,N}(img::AbstractArray{T,N}, kern::AbstractArray{K,N}, border::AbstractString, value)
if border == "circular" && size(img) == size(kern)
out = real(ifftshift(ifft(fft(img).*fft(kern))))
elseif border != "inner"
prepad = [div(size(kern,i)-1, 2) for i = 1:N]
postpad = [div(size(kern,i), 2) for i = 1:N]
fullpad = [nextprod([2,3], size(img,i) + prepad[i] + postpad[i]) - size(img, i) - prepad[i] for i = 1:N]
A = padarray(img, prepad, fullpad, border, convert(T, value))
krn = zeros(typeof(one(T)*one(K)), size(A))
indexesK = ntuple(d->[size(krn,d)-prepad[d]+1:size(krn,d);1:size(kern,d)-prepad[d]], N)::NTuple{N,Vector{Int}}
AF = ifft(fft(A).*fft(krn))
out = Array(realtype(eltype(AF)), size(img))
end
out
end
Test:
julia> @code_warntype ifi(rand(3,3), rand(3,3), "replicate", 0)
Variables:
#self#::#ifi
img::Array{Float64,2}
kern::Array{Float64,2}
border::ASCIIString
value::Int64
prepad::Box
...
Now comment out the indexesK = ...
line (the output of which is not used at all). Suddenly prepad
is inferred as Array{Int, 1}
.