Low-pass filter for image
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Image Analyst
2021 年 4 月 25 日
@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);
回答 (2 件)
Walter Roberson
2011 年 1 月 30 日
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
2016 年 3 月 3 日
just give p a value like 10 and run the code. should be fine
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!