2010-09-16 74 views

回答

14

由於FFT2IFFT2double類型和single的兩個僅支持輸入,您的image data(這很可能uint8類型)被轉換由FFT2處理之前鍵入double第一。因此,你必須使用功能UINT8恢復原始圖像的輸出圖像inv轉換回一個無符號的8位整數:

>> img = imread('peppers.png'); %# Load a sample image 
>> fft = fft2(img); %# Get the Fourier transform 
>> inv = ifft2(fft); %# Get the inverse Fourier transform 
>> inv = uint8(inv); %# Convert to uint8 
>> imshow(inv);  %# Show the image 
>> isequal(img,inv) %# Test if inv matches the original image img 

ans = 

    1    %# It does! 

注:作爲一個額外的小費,我會避免命名變量fftinv,因爲這些名稱的函數已經存在於MATLAB中。

2

此外,如果您嘗試對顏色(24位)圖像執行FFT,請注意imread()將返回M x N x 3數組。因此,您應該分別在每個R/G/B通道上執行FFT。

See this瞭解詳情。

+3

實際上,看起來FFT2會爲您處理。如果在命令窗口中鍵入'type fft2',可以看到一個3-D輸入'x'導致fft(fft(x,[],2),[],1)'的運行,在第二維和第一維上進行FFT,而2-D輸入「x」(如果您單獨通過每個彩色平面)將導致對[FFTN]的調用(http://www.mathworks.com/help/techdoc) /ref/fftn.html)。比較每種方法,結果之間的最大絕對像素差異大約爲5.6e-10,可能是由於操作順序的差異。總之,這兩者幾乎相當。 – gnovice 2010-09-16 18:39:52

+0

+1分享此功能... – 2010-09-16 18:53:41