# Using fftn to filter 4D image (3D video)

4 views (last 30 days)
Ryan Woodall on 20 Dec 2021
Answered: Prachi Kulkarni on 11 Jan 2022
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:
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!

Prachi Kulkarni on 11 Jan 2022
Hi,
Let the array arr be of size h-by-w-by-d-by-t.
The filtered_video should be trimmed as follows to get the same output as given by the convn convolution function.
h_range = floor(h/2+1):floor(h/2+1)+h-1;
w_range = floor(w/2+1):floor(w/2+1)+w-1;
d_range = floor(d/2+1):floor(d/2+1)+d-1;
t_range = floor(t/2+1):floor(t/2+1)+t-1;
trimmed_filtered_video = filtered_video(h_range,w_range,d_range,t_range);

### Categories

Find more on Digital Filtering in Help Center and File Exchange

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by