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

2 visualizaciones (últimos 30 días)
Ryan Woodall
Ryan Woodall el 20 de Dic. de 2021
Respondida: Prachi Kulkarni el 11 de En. de 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:
arr_pad = padarray(arr, ceil(size(arr)/2)+1, 'replicate', 'both');
kernel_pad = padarray(arr, ceil(size(arr)/2)+1, 'replicate', 'both');
arr_FFT = fftn(arr_pad);
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!

Respuestas (1)

Prachi Kulkarni
Prachi Kulkarni el 11 de En. de 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);

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by