필터 지우기
필터 지우기

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 CenterFile Exchange에서 Frequency Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by