Question

I Read the image 'abc.jpg' im MATLAB and covert its data type to double.Display the image. Store the size of image in M and N. All the loops of x, y, u and v runs till image size. enter image description here

Now I want to know 1:how Multiply the above input image by (-1)^x+y To Center the Transform To U = M/2 And V = N/2.

2:multiply it with ideal HPF(High Pass Filter) with value of D=50. where D is the radius size of Ideal HPF.

After Multiplying with Ideal HPF the resulting image will look like this. enter image description here

Was it helpful?

Solution 4

n1=rgb2gray(imread('fin.jpg'));
imshow(n1);

F=fft2(double(n1));

%Calculate Size of Image

[M,N]=size(F);

%Distance Radius Size

D0=50;
n=2;
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);

%Distance Calculation for High Pass Filter using Distance Formula

D=sqrt(U.^2+V.^2);

H=double(D>D0);
subplot(2,1,1);
imshow(fftshift(H));
G=H.*F;
g=real(ifft2(double(G)));
[a,b]=size(g);
for x=1:a
    for y=1:b
        sharpen_image(x,y)=(g(x,y))*(-1)^((x)+(y));
    end
end
figure
imshow(sharpen_image);

OUTPUT

enter image description here

OTHER TIPS

Since you placed a bounty, I wrote an enhanced reply.

I should mention that you might want to consider using an appropriate window filter before calculating your fft to avoid border artifacts (I included this option in the code below). I hope it helps.

Here is a suggestion for your code:

a=rgb2gray(imread('abc.jpg'))
D=50;
[x y i]=size(a);

Generating a Hanning window to suppress border artifacts: (optional)

hannx = hann(x); hanny = hann(y);
Hann = hannx * hanny';

Calculating the 2D fft of the weighted image: (remove .*Hann if you don't want it)

FreqDomain=fftshift(fft2(a.*Hann));

Generating a disc-shaped binary mask with radius D:

Mask = fspecial('disk',D)==0;
Mask = imresize(padarray(Mask, [floor((x/2)-D) floor((y/2)-D)], 1, 'both'), [x y]);

Masking the frequency domain image:

MaskedFFT=FreqDomain.*Mask;

Computing inverse FFT:

Filtereda=ifft2(MaskedFFT, 'symmetric');

Note that the code assumes D is smaller than x/2 and y/2

An ideal HPF is a 0-1 filter that reduce to zero all frequencies lower than D.

>> sz = size( a ); % size of image, assuming image is gray-level and not color
>> [u v] = meshgrid( .5 * linspace( -sz(1), sz(1), sz(1) ),...
                     .5 * linspace( -sz(2), sz(2), sz(2) ) ); % construct the grid for the freq domain
>> hpf = ifftshift( sqrt( u.^2 + v.^2 ) <= D ); % construct the filter
>> A = fft2( a ); 
>> fA = A.*hpf; % apply the filter in freq domain
>> fa = abs( ifft2( fA ) ); % back to image domain

I'm not sure to understand exactly what you want to do, but it seems like you're trying to implement a high pass filter based on a FFT.

That is how I would proceed:

a=imread('abc.jpg')
FreqDomain=fftshift(fft(a));

(fftshift is centering the 0 frequency component)

And then crop FreqDomain to whichever cutoff you like, and apply ifft to the cropped image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top