I have a gray-scale image. I divided the image into non-overlapping blocks of 64x64 pixels.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have two questions. How can I apply the Discrete Fourier Transform (DFT) to each block image and set to 0 the amplitude of low-frequency components (points within 3 pixels from the center in the frequency domain)? How can I do that? My second question is that I am going to find six points with the maximum amplitude in the frequency domain. Each of these points corresponds to a 2Dsine wave w(x, y) = a*sin(2*pi*f(x*cos(theta) + y*sin(theta) + phi), where a, f, theta, and phi represent the amplitude, frequency, direction, and phase, respectively. How can I obtain a, f, theta, phi, and w(x, y) for a block image? I only want to use Matlab. Thank you very much in advance.
I used the following code to use frequency domain. f = fft2(im); fshifted = fftshift(f); fabs = abs(fshifted);
0 Commenti
Risposte (1)
Shubham
il 5 Apr 2023
Hi Afra,
To set the amplitude of low-frequency components to 0, you can apply a mask to the Fourier transformed image. Here's how you can modify your code:
f = fft2(im);
fshifted = fftshift(f);
fabs = abs(fshifted);
% define a mask
[x,y] = meshgrid(1:size(im,2),1:size(im,1));
center_x = size(im,2)/2;
center_y = size(im,1)/2;
r = 3;
mask = sqrt((x - center_x).^2 + (y - center_y).^2) > r;
% apply the mask to the Fourier transformed image
fmasked = fshifted .* mask;
Here, we first define a mask using meshgrid, where the values within a certain radius of the center are set to 0, and the values outside are set to 1. We then apply this mask to the Fourier transformed image by element-wise multiplication.
To find the six points with the maximum amplitude in the frequency domain, you can use the maxk function in MATLAB. Here's an example:
% find the six points with the maximum amplitude
[maxvals, maxidx] = maxk(fabs(:), 6);
% convert linear indices to subscripts
[maxy, maxx] = ind2sub(size(im), maxidx);
% extract corresponding parameters for each point
a = maxvals;
f = sqrt((maxx - center_x).^2 + (maxy - center_y).^2);
theta = atan2(maxy - center_y, maxx - center_x);
phi = angle(fshifted(maxidx));
w = @(x,y) a .* sin(2*pi*f.*(x*cos(theta) + y*sin(theta) + phi));
Here, we first use the maxk function to find the indices of the six points with the largest amplitude in fabs. We then convert these linear indices to subscripts using the ind2sub function. Finally, we extract the corresponding amplitude, frequency, phase, and direction parameters for each point and define the corresponding sine wave function w(x, y) using an anonymous function.
Note that in the above code, we assume that the image is square, and the size of the image is even. If your image is rectangular or the size is odd, you may need to adjust the code accordingly.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!