Deconvolution/2D+: Difference between revisions

Content added Content deleted
Line 870: Line 870:


function flatnested2d(a, siz)
function flatnested2d(a, siz)
dim1, dim2 = length(a), length(a[1])
@assert(dim1 <= siz[1] && dim2 <= siz[2])
ret = zeros(Int, prod(siz))
ret = zeros(Int, prod(siz))
for i in 1:dim1, j in 1:dim2
for i in 1:length(a), j in 1:length(a[1])
ret[siz[2] * (i - 1) + j] = a[i][j]
ret[siz[2] * (i - 1) + j] = a[i][j]
end
end
Line 880: Line 878:


function flatnested3d(a, siz)
function flatnested3d(a, siz)
dim1, dim2, dim3 = length(a), length(a[1]), length(a[1][1])
@assert(dim1 <= siz[1] && dim2 <= siz[2] && dim3 < siz[3])
ret = zeros(Int, prod(siz))
ret = zeros(Int, prod(siz))
for i in 1:dim1, j in 1:dim2, k in 1:dim3
for i in 1:length(a), j in 1:length(a[1]), k in 1:length(a[1][1])
ret[siz[2] * siz[3] * (i - 1) + siz[3] * (j - 1) + k] = a[i][j][k]
ret[siz[2] * siz[3] * (i - 1) + siz[3] * (j - 1) + k] = a[i][j][k]
end
end
Line 890: Line 886:


topow2(siz) = map(x -> nextpow(2, x), siz)
topow2(siz) = map(x -> nextpow(2, x), siz)
deconv1d(f1, g1, expecteddim1) = Int.(round.(deconv(Float64.(g1), Float64.(f1))))

function deconv1d(f1, g1, expecteddim1)
h1 = deconv(Float64.(g1), Float64.(f1))
Int.(round.(h1))
end


function deconv2d(f2, g2, xd2)
function deconv2d(f2, g2, xd2)
Line 900: Line 892:
h2 = Int.(round.(real.(ifft(fft(flatnested2d(g2, siz)) ./
h2 = Int.(round.(real.(ifft(fft(flatnested2d(g2, siz)) ./
fft(flatnested2d(f2, siz))))))
fft(flatnested2d(f2, siz))))))
[[h2[siz[2] * (i - 1) + j] for j in 1:xd2[2]] for i in 1:xd2[1]]
ret = Vector{Vector{Int}}()
for i in 1:xd2[1]
v = Vector{Int}()
for j in 1:xd2[2]
push!(v, h2[siz[2] * (i - 1) + j])
end
push!(ret, v)
end
ret
end
end


Line 915: Line 899:
h3 = Int.(round.(real.(ifft(fft(flatnested3d(g3, siz)) ./
h3 = Int.(round.(real.(ifft(fft(flatnested3d(g3, siz)) ./
fft(flatnested3d(f3, siz))))))
fft(flatnested3d(f3, siz))))))
[[[h3[siz[2] * siz[3] *(i - 1) + siz[3] * (j - 1) + k] for k in 1:xd3[3]]
ret = Vector{Vector{Vector{Int}}}()
for i in 1:xd3[1]
for j in 1:xd3[2]] for i in 1:xd3[1]]
v2 = Vector{Vector{Int}}()
for j in 1:xd3[2]
v = Vector{Int}()
for k in 1:xd3[3]
push!(v, h3[siz[2] * siz[3] *(i - 1) + siz[3] * (j - 1) + k])
end
push!(v2, v)
end
push!(ret, v2)
end
ret
end
end