1
$\begingroup$

As a generalization of the following questions:

I would like to know how to handle the n dimensional general case both for Upsampling and Downsampling.
The above questions deals with 1D and 2D and I wonder how to handle the general nD case.
The answer should be practical, namely emphasize implementation considerations.

$\endgroup$
3
  • $\begingroup$ the same; the thing you want is inherently a separable kernel, so you can fist 1-D interpolate in one, then in the other dimension. $\endgroup$ Feb 20, 2022 at 19:29
  • $\begingroup$ @MarcusMüller, It's a bit trickier in high dimensions. As the slice is N - 1 which requires a delicate handling. $\endgroup$
    – Royi
    Feb 28, 2022 at 17:45
  • $\begingroup$ @Royi interesting! Reading up on this :) $\endgroup$ Feb 28, 2022 at 20:05

1 Answer 1

1
+100
$\begingroup$

The general $ n $ dimension case can be solved with the following loop:

for dimIdx in 1:ndims(tX)
    tXDft = fft(tX, dimIdx);
    tXDft = PadOrCrop(tXDft, dimIdx);
    tXDft = FixSlice(tXDft, dimIdx)
    tX    = ifft(tXDft, dimIdx);
end

The tricky parts are handling the cropping (Downsampling) or padding (Upsampling) for the $ n - 1 $ dimensions slice.

One way to solve it is to recursively work on smaller dimensions slices until we get to 1D / 2D slice which is solved in the questions you linked to.

Another way is to define a slice indexing.
Assume the array has indices of: (1:5, 1:10, 1:15, 1:20) then the the $ i $ -th slice in the $ d $ -th dimensions has the indices, for i = 4 and d = 2 (1:5, 4, 1:15, 1:20).

Those slices are the elements we can treat as scalars in the 1D case. Namely split them or add them in order to compensate for Upsampling / Downsampling.

So basically we do, 1D DFT, then we apply cropping / padding according to need at the dimension in work, then we extract the slices at the bin which needs to be fixed and add them / split them then Inverse DFT.

$\endgroup$
1
  • $\begingroup$ Please elaborate on the implementation. $\endgroup$
    – Mark
    Feb 28, 2022 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.