フィルターのクリア

Low-pass filter for image

2 ビュー (過去 30 日間)
amitesh kumar
amitesh kumar 2011 年 1 月 30 日
コメント済み: Image Analyst 2021 年 4 月 25 日
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 件のコメント
mohammad nemat
mohammad nemat 2021 年 4 月 25 日
how we can determine value for P? what's P value
Image Analyst
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
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()
  1 件のコメント
amitesh kumar
amitesh kumar 2011 年 1 月 30 日
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.
plz consider
H=double(D<=P);
by mistake i wrote as H=double(D<=512*512)
....

サインインしてコメントする。


Muhammad Vellani
Muhammad Vellani 2016 年 3 月 3 日
just give p a value like 10 and run the code. should be fine

カテゴリ

Help Center および File ExchangeFrequency Transformations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by