Quite right. It is numerical data for which there is no simple scalar function.
Specifically, a 3D image volume consisting of a stack of 2D radiological [CT] image slices.
Thanks for your suggestion and link.
However, my implementation, as below, takes far too long to be of use.
#=
rows_coords: Vector{Float64} (512,)
cols_coords: Vector{Float64} (512,)
slices_coords: Vector{Float64} (802,)
=#
nodes = (rows_coords, cols_coords, slices_coords)
#=
seriesImgVlm: Array{Float64, 3}(512, 512, 802)
=#
interpolatedImgVlm = interpolate(nodes, seriesImgVlm, Gridded(Linear()))
#=
n_rows: 512
n_cols: 512
n_slices: 802
=#
gradientMgntdSqrdImgVlm = zeros(Float64, n_rows, n_cols, n_slices)
@time begin
for k = 1:n_slices
slice_coord = slices_coords[k]
for j = 1:n_cols
col_coord = cols_coords[j]
for i = 1:n_rows
row_coord = rows_coords[i]
gradientImgVlm =
Interpolations.gradient(interpolatedImgVlm, row_coord, col_coord, slice_coord)
gradientMgntdSqrdImgVlm[i, j, k] = dot(gradientImgVlm, gradientImgVlm)
end
end
end
end
The timer reports, for the 2nd run - after compilation is done:
134.354073 seconds (1.47 G allocations: 43.902 GiB, 6.24% gc time)
As I am still learning Julia, coming from a C++/Python background, I would appreciate any advice on how to improve the performance of calculating the magnitude of the gradient of a 3D array. The code I am rewriting from C++ requires repeated gradient calculations, so speed is essential. I had first considered using diff(), but would like to avoid having to pad the arrays to deal with the boundaries.
Also, the use of Interpolations.jl or FiniteDifferences.jl was recommended in Julia discourse.