I’m wondering how one would go about upsampling an array, I’ve come across interpolations.jl, to interpolate the newly created elements in the scaled array but I’m not certain how this can be used to upscale an array. Is there, by any chance, a package that handles array upsampling?
You can use interpolations directly and index with real numbers within the range of valid indices (unless you want to use extrapolations as well). See the readme of the package you linked for more details on the parameters
julia> using Interpolations
julia> A = interpolate([1. 2; 3 4], BSpline(Linear()), OnGrid())
2×2 interpolate(::Array{Float64,2}, BSpline(Linear()), OnGrid()) with element type Float64:
1.0 2.0
3.0 4.0
julia> A[1:0.5:2, 1:0.5:2]
3×3 Array{Float64,2}:
1.0 1.5 2.0
2.0 2.5 3.0
3.0 3.5 4.0
Images.jl offers a high-level interface for resizing which uses Interpolations.jl under the hood
I guess Images.jl isn’t suitable since I’m using multi-dimensional arrays?
For the interpolations.jl method, how could you taken an array and, for example, double (or triple) it’s size. Say I want to double the following array: [1. 3 3 4 5 6; 7 8 9 10 11 12] (2x6)
You might want to try Images.jl anyway–I don’t think it has any particular restrictions to 2-dimensional arrays (that’s one of it’s best features, in my opinion).
Using interpolations directly, you just need to give the right range indices. 1:0.5:2 is a range with values [1, 1.5, 2], which is why you end up with 3 (instead of 4) rows in the result. If you want 4 elements in your range, you just need to pick the appropriate step size. In this case, it would be exactly 1/3 which you can represent as an exact Rational number in Julia with 1//3:
julia> length(1 : 1//3 : 2)
4
And you can use that range for to index into the interpolation:
Thanks, it seems that imresize is using bicubic interpolation? There probably is a way to change this?
It’s not really that important though, you guys already solved my problems!