2016-01-23 75 views
0

我有一張由2張相同圖像組成的圖像,其中一張被翻譯。使用頻域進行圖像處理 - 複製圖像

input

現在,我要修復它。我使用變換傅立葉變換的性質如下:

$ 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

任何幫助將不勝感激。 謝謝。

+0

你想要做的是註冊。看看ImageJ中的TurboReg插件,它確實很好。我知道一些基本的算法也已經在MatLab中實現。 – FiReTiTi

+0

謝謝,但不幸的是我不能使用插件。 – daniel

+0

所有的源代碼(基本的Java)也可用,以防萬一你想翻譯它。我對註冊有很大的需求,TurboReg是我發現的最好的算法。 – FiReTiTi

回答

0
  • 交換x和y在分割陣列
  • fftshift
  • 除去的定義添加-1在指數的argumend爲計數器
  • 添加結果繪製

    一個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]) 
    
+0

謝謝!有用! – daniel