How to calculate a gradient by fft ???
28 次查看(过去 30 天)
显示 更早的评论
Hi;
someone can help me, how to calculate Gradient using fft ???
0 个评论
采纳的回答
David Young
2011-9-20
It's still not clear what you mean by 'simple "gradient"' - that could refer to a variety of things.
One possibility is that you mean just the differences between adjacent values - what you'd get by computing
diff(im, 1, 2) % x differences - x component of gradient
and
diff(im, 1, 1) % y differences - y component of gradient
for example. You can do a similar operation in the frequency domain using the fact that the differentiation operator transforms to multiplication with ik (where k is the transform variable). The code looks like this for differentiating with respect to x:
im = imread('pout.tif'); % data
% compute differencing operator in the frequency domain
nx = size(im, 2);
hx = ceil(nx/2)-1;
ftdiff = (2i*pi/nx)*(0:hx); % ik
ftdiff(nx:-1:nx-hx+1) = -ftdiff(2:hx+1); % correct conjugate symmetry
% compute "gradient" in x using fft
g = ifft2( bsxfun(@times, fft2(im), ftdiff) );
imshow(g, []); % see result
As you can see, it's simpler to do it in the space domain. Why use the FFT?
7 个评论
David Young
2011-9-28
Well, you have to think about the shapes of the arrays. Differentiating with respect to x means multiplying each row of the the Fourier transform by ftdiff. If you want to differentiate with respect to y, you have to multiply each column by ftdiff. Changing the size of ftdiff is a start, but you also have to change it from a row vector to a column vector.
更多回答(1 个)
Walter Roberson
2011-9-19
Is that plain "gradient", or is it "conjugate gradient" ?
(I notice you posted the same question to some other locations, all of which seem to have replied asking for clarification.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!