使用频域的图像处理 - 复制图像
Image processing using the frequency domain - duplicate image
我有一张图片,由两张相同的图片组成,其中一张已翻译。
现在,我想修复它。我用的是transform fourier的翻译属性:
$f(x-x_0,y-y_0)\leftrightarrowF(u,v)e^{-2{\pi}i(ux_0/{N}+ vy_0/M)}$
我测量了两张图片之间的距离:x距离是24像素,y距离是4像素。在代码中:x_d 和 y_d.
然后我就将频域图像中的所有像素除以公式+1的指数表达式(1来自未翻译的图像)。
我想不通是什么问题...
这是我的代码:
function [ ] = f( )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
FileName='dog.tif';
%--- Read Image ---
im = readImage(FileName);
imshow(im);
%--- apply FFT on the given image ---
fftIm = fftshift(fft2(im));
%--- apply LOG and abs for plotting the transform ---
fLog = log(1 + abs(fftIm));
%----modify the image in the frequency domain-------
fftImMod=fftIm;
x_d=24; %x distance between the 2 images
y_d=4; %y distance between the 2 images
N = 305; %the dimensions of the image NxM = 305x305
M = 305; %the dimensions of the image NxM = 305x305
for r=1:size(fftIm,1)
for k=1:size(fftIm,2)
divisionVal = 1+exp((-2*(pi)*1i)*(r*x_d/N + k*y_d/M));
fftImMod(r,k)=fftIm(r,k)/divisionVal;
end;
end;
%--- apply LOG and abs for plotting the modified transform ---
fLogAfterMod = log(1 + abs(fftImMod));
%--- return to the image space ---
result=ifft2(fftshift(fftImMod));
% --- display results ---
colormap(gray)
subplot(2,2,1),imagesc(im); title('Original Image')
subplot(2,2,2),imagesc(fLog); title('Fourier Image')
subplot(2,2,3),imagesc(fLogAfterMod); title('Modified Fourier')
subplot(2,2,4),imagesc(real(result)); title('Result Image')
end
结果如下:
result
如有任何帮助,我们将不胜感激。
谢谢。
- 在除法数组的定义中交换了 x 和 y
- 删除了 fftshift
- 在计数器的指数参数中添加了 -1
为结果绘图添加了 BW 限制
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
FileName='/tmp/me4iX.jpg';
%--- Read Image ---
im = imread(FileName);
im=im(:,:,1)
%--- apply FFT on the given image ---
fftIm = (fft2(im));
%--- apply LOG and abs for plotting the transform ---
fLog = log(1 + abs(fftIm));
%----modify the image in the frequency domain-------
fftImMod=fftIm;
x_d=24; %x distance between the 2 images
y_d=4; %y distance between the 2 images
N = 305; %the dimensions of the image NxM = 305x305
M = 305; %the dimensions of the image NxM = 305x305
for r=1:size(fftIm,1)
for k=1:size(fftIm,2)
divisionVal(r,k) = 1+exp((-2*(pi)*1i)*((r-1)*y_d/N + (k-1)*x_d/M));
end;
end;
fftImMod=fftIm./divisionVal;
%--- apply LOG and abs for plotting the modified transform ---
fLogAfterMod = log(1 + abs(fftImMod));
%--- return to the image space ---
N=60;
result=ifft2((fftImMod([1:N end-N-2:end],[1:N end-N-2:end])));
% --- display results ---
colormap(gray)
subplot(2,2,1),imagesc(im); title('Original Image')
subplot(2,2,2),imagesc(fLog); title('Fourier Image')
subplot(2,2,3),imagesc(fLogAfterMod); title('Modified Fourier')
subplot(2,2,4),imagesc(abs(result)); title('Result Image')
%set(gca,'clim',[0 250])
我有一张图片,由两张相同的图片组成,其中一张已翻译。
现在,我想修复它。我用的是transform fourier的翻译属性:
$f(x-x_0,y-y_0)\leftrightarrowF(u,v)e^{-2{\pi}i(ux_0/{N}+ vy_0/M)}$
我测量了两张图片之间的距离:x距离是24像素,y距离是4像素。在代码中:x_d 和 y_d.
然后我就将频域图像中的所有像素除以公式+1的指数表达式(1来自未翻译的图像)。
我想不通是什么问题...
这是我的代码:
function [ ] = f( )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
FileName='dog.tif';
%--- Read Image ---
im = readImage(FileName);
imshow(im);
%--- apply FFT on the given image ---
fftIm = fftshift(fft2(im));
%--- apply LOG and abs for plotting the transform ---
fLog = log(1 + abs(fftIm));
%----modify the image in the frequency domain-------
fftImMod=fftIm;
x_d=24; %x distance between the 2 images
y_d=4; %y distance between the 2 images
N = 305; %the dimensions of the image NxM = 305x305
M = 305; %the dimensions of the image NxM = 305x305
for r=1:size(fftIm,1)
for k=1:size(fftIm,2)
divisionVal = 1+exp((-2*(pi)*1i)*(r*x_d/N + k*y_d/M));
fftImMod(r,k)=fftIm(r,k)/divisionVal;
end;
end;
%--- apply LOG and abs for plotting the modified transform ---
fLogAfterMod = log(1 + abs(fftImMod));
%--- return to the image space ---
result=ifft2(fftshift(fftImMod));
% --- display results ---
colormap(gray)
subplot(2,2,1),imagesc(im); title('Original Image')
subplot(2,2,2),imagesc(fLog); title('Fourier Image')
subplot(2,2,3),imagesc(fLogAfterMod); title('Modified Fourier')
subplot(2,2,4),imagesc(real(result)); title('Result Image')
end
结果如下:
result
如有任何帮助,我们将不胜感激。 谢谢。
- 在除法数组的定义中交换了 x 和 y
- 删除了 fftshift
- 在计数器的指数参数中添加了 -1
为结果绘图添加了 BW 限制
%UNTITLED Summary of this function goes here % Detailed explanation goes here FileName='/tmp/me4iX.jpg'; %--- Read Image --- im = imread(FileName); im=im(:,:,1) %--- apply FFT on the given image --- fftIm = (fft2(im)); %--- apply LOG and abs for plotting the transform --- fLog = log(1 + abs(fftIm)); %----modify the image in the frequency domain------- fftImMod=fftIm; x_d=24; %x distance between the 2 images y_d=4; %y distance between the 2 images N = 305; %the dimensions of the image NxM = 305x305 M = 305; %the dimensions of the image NxM = 305x305 for r=1:size(fftIm,1) for k=1:size(fftIm,2) divisionVal(r,k) = 1+exp((-2*(pi)*1i)*((r-1)*y_d/N + (k-1)*x_d/M)); end; end; fftImMod=fftIm./divisionVal; %--- apply LOG and abs for plotting the modified transform --- fLogAfterMod = log(1 + abs(fftImMod)); %--- return to the image space --- N=60; result=ifft2((fftImMod([1:N end-N-2:end],[1:N end-N-2:end]))); % --- display results --- colormap(gray) subplot(2,2,1),imagesc(im); title('Original Image') subplot(2,2,2),imagesc(fLog); title('Fourier Image') subplot(2,2,3),imagesc(fLogAfterMod); title('Modified Fourier') subplot(2,2,4),imagesc(abs(result)); title('Result Image') %set(gca,'clim',[0 250])