Clear Filters
Clear Filters

anti aliasing filter problem

6 views (last 30 days)
Rana
Rana on 4 Oct 2023
Edited: Sudarsanan A K on 23 Oct 2023
the following is my code I'm not sure why it inverts the image upside down after doing the operation
HPsamp = HP(1:2:end, 1:2:end);
LPsamp = LP(1:2:end, 1:2:end);
HPsampfreq = (abs(fftshift(fft2(HPsamp))) / 100);
LPsampfreq = (abs(fftshift(fft2(LPsamp))) / 100);
HPsamp2 = HP(1:4:end, 1:4:end);
LPsamp2 = LP(1:4:end, 1:4:end);
HPsamp2freq = (abs(fftshift(fft2(HPsamp2))) / 100);
LPsamp2freq = (abs(fftshift(fft2(LPsamp2))) / 100);
gausshalf = fspecial('gaussian', 250, 0.05);
gaussquart = fspecial('gaussian', 125, 0.3);
HPfilthalf = imfilter(gausshalf, HPsamp);
HPfiltquart = imfilter(gaussquart, HPsamp2);
HPfilthalffreq = (abs(fftshift(fft2(HPfilthalf))) / 200);
HPfiltquartfreq = (abs(fftshift(fft2(HPfiltquart))) / 200);

Answers (1)

Sudarsanan A K
Sudarsanan A K on 23 Oct 2023
Edited: Sudarsanan A K on 23 Oct 2023
Hello Rana,
I understand that you are using the "imfilter()" function for filtering your down sampled images and wanted to perform frequency domain analysis. I note that you are experiencing that the filtered images "HPfilthalf" and "HPfiltquart" are upside down after the filtering operation using the function "imfilter()".
This happens because the function "imfilter()" performs multidimensional filtering using correlation by default, which is the same way that "filter2()" performs filtering and expects the arguments as follows:
B = imfilter(A,h)
where, "A" is the multidimensional array and "h" is the multidimensional filter.
I observe that the input arguments are swapped in positions in the code that you provided. As I mentioned, since the "imfilter()" uses correlation for the filtering operation, this causes an unexpected behaviour as you observed, the upside-down nature of the filtered output.
There are two ways you can resolve this issue:
  1. Use proper order for the input arguments: Pass the image to be filtered as the first argument and the filter kernel as the second argument.
  2. Use "conv" option for filtering: By default, "imfilter()" uses correlation because the toolbox filter design functions produce correlation kernels. Use the optional parameter to use convolution as follows:
imfilter(h,A,'conv')
Note that convolution is commutative and this will produce the desired result irrespective of the order of "A" and "h".
To know more about the "imfilter()" function, you can additionally refer to the MathWorks documentation in the link:
I hope this helps!

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!