I have a 3D video, resulting in a 4D array. Dimensions are [128 128 9 15], with 9 z-slices and 15 time points. I want to apply a seperable 4D filter to this signal. To do so, I have created a 4D kernel, also of size [128 128 9 15] by multiplying the 1D component of each dimension using pagemtimes, where the sizes of each filter is [1 128], [1 128], [1 9], [1 15], respectively. For simplicity, assume all are 1D centered Gaussians.
filter_xy = filter_x' * filter_y;
filter_xyz = pagemtimes(filter_xy, reshape(filter_z, [1 1 length(filter_z)]) );
filter_xyzt = pagemtimes(filter_xyz, reshape(filter_t, [1 1 1 length(filter_t)]));
I use the following code to apply the 4D filter kernel:
arr_pad = padarray(arr, ceil(size(arr)/2)+1, 'replicate', 'both');
kernel_pad = padarray(arr, ceil(size(arr)/2)+1, 'replicate', 'both');
kernel_FFT = fft(kernel_pad);
filtered_video = ifftn(arr_FFT.*kernel_FFT);
How do I trim the array 'filtered_video' to get it back to the original array dimensions, corresponding to the data from the original 4D-array 'arr'? Do I need to use an fftshift anywhere?
Thanks for the help!