Image alteration problem when using a 2D Fourier shifting
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Xavier SaladeVerte
am 23 Apr. 2018
Kommentiert: Matt J
am 24 Apr. 2018
Hello everyone,
I would like to translate a picture from a number of pixels with a 2D Fourier shifting and I am having a problem when using this function :
function y = FourierShift2D(x, delta)
%
% y = FourierShift(x, [delta_x delta_y])
%
% Shifts x by delta cyclically. Uses the fourier shift theorem.
%
% Real inputs should give real outputs.
%
% By Tim Hutt, 26/03/2009
% Small fix thanks to Brian Krause, 11/02/2010
% The size of the matrix.
[N, M, L] = size(x);
% FFT of our possibly padded input signal.
X = fft2(x);
% The mathsy bit. The floors take care of odd-length signals.
x_shift = exp(-i * 2 * pi * delta(1) * [0:floor(N/2)-1 floor(-N/2):-1]' / N);
y_shift = exp(-i * 2 * pi * delta(2) * [0:floor(M/2)-1 floor(-M/2):-1] / M);
% Force conjugate symmetry. Otherwise this frequency component has no
% corresponding negative frequency to cancel out its imaginary part.
if mod(N, 2) == 0
x_shift(N/2+1) = real(x_shift(N/2+1));
end
if mod(M, 2) == 0
y_shift(M/2+1) = real(y_shift(M/2+1));
end
Y = X .* (x_shift * y_shift);
% Invert the FFT.
y = ifft2(Y);
% There should be no imaginary component (for real input
% signals) but due to numerical effects some remnants remain.
if isreal(x)
y = real(y);
end
end
The picture obtained is systematically altered as you can see in the attached file, and I have no idea where it comes from. I tried using other functions, and faced the same issue. If someone would have a clue on how to solve the problem, I would appreciate it.
Thanks !
0 Kommentare
Akzeptierte Antwort
Matt J
am 23 Apr. 2018
Bearbeitet: Matt J
am 23 Apr. 2018
Though I discourage you from using it, there is nothing wrong with FourierShift2D. The problem was that imshow requires the resulting image, if it is in floating point form, to be normalized to be less than one.
A=imread('zebre.jpg');
B=FourierShift2D(double(A), delta);
B=B/max(B(:)); %resulting image
imshow(B)
1 Kommentar
Weitere Antworten (1)
Matt J
am 23 Apr. 2018
Bearbeitet: Matt J
am 23 Apr. 2018
Don't use Fourier transforms to do shifts. It's an important theoretical property of Fourier transforms, but a horribly inefficient way to shift a signal/image in practice. Use re-interpolation instead,
delta=[30.4,20.2];
A=imread('zebre.jpg');
[m,n,p]=size(A);
mr=0:m-1;
nr=0:n-1;
pr=0:p-1;
F=griddedInterpolant({mr,nr,pr},double(A));
x=mod(mr-delta(1),m);
y=mod(nr-delta(2),n);
z=pr;
B=F({x,y,z}); %The shifted image
B = B./max(B(:));
imshow( B )
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!