Low-pass filter for image
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
When I am trying to run the following code, it is giving an error
[ ??? Input argument "P" is undefined.
Error in ==> idealfilter at 13
H=double(D<=P); ]
Please guide me to remove this error. My image size is 512*512
function idealfilter(X,P)
f=imread('lena.jpg');
[M,N]=size(f);
F=fft2(double(f));
u=0:(M-1);
v=0:(N-1);
idx=find(u>M/2);
u(idx)=u(idx)-M;
idy=find(v>N/2);
v(idy)=v(idy)-N;
[V,U]=meshgrid(v,u);
D=sqrt(U.^2+V.^2);
H=double(D<=512*512);
G=H.*F;
g=real(ifft2(double(G)));
imshow(f),figure,imshow(g,[ ]);
end
4 comentarios
Image Analyst
el 25 de Abr. de 2021
@mohammad nemat, if the intent is to make a largest circle that can fit in the image, it should be
f=imread('lena.jpg');
[rows, columns, numberOfColorChannels] = size(f);
radius = min([rows, columns] / 2);
H = double(D <= radius);
Respuestas (2)
Walter Roberson
el 30 de En. de 2011
You are not executing the same code that you have shown us. Please ensure that you have saved your source file, and for good measure issue the command
clear idealfilter
in case it has gotten the wrong version stuck in memory somehow.
Your line of source,
D=sqrt(U.^2+V.^2);
looks as if you are calculating a Euclidean distance, and the line you indicate the error as being on,
H=double(D<=P);
would then be consistent with finding a circle of radius P around what you would get if you were to cut the image in to four quarters and flip the right half left-to-right and flip the bottom half top-to-bottom. Looks a bit suspicious to me, but you might have your reasons.
The line that appears in your code, though,
H=double(D<=512*512)
would only be equivalent if your radius P was 512*512, which seems unlikely. A radius of 512 would seem to be more suitable.
I believe it is possible that you have gotten confused between two formulations of the same expression,
sqrt(X.^2 + Y.^2) <= R
and the more optimized
(X.^2 + Y.^2) <= R^2
You are using the sqrt() version, but you appear to be using it with the R^2 comparison rather than the R comparison suitable for sqrt()
Muhammad Vellani
el 3 de Mzo. de 2016
just give p a value like 10 and run the code. should be fine
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!