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

2 ビュー (過去 30 日間)
Ryan Woodall
Ryan Woodall 2021 年 12 月 20 日
回答済み: Prachi Kulkarni 2022 年 1 月 11 日
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!

回答 (1 件)

Prachi Kulkarni
Prachi Kulkarni 2022 年 1 月 11 日
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);

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by