2016-09-13 32 views
0

我想灰度圖像的大小歸到一個在MATLAB(reference正火灰度圖像的大小,以一個

幻燈片18顯示的結果應該是什麼樣子,但由於某些原因,當我運行我的代碼,我得到一個完整的黑色圖像輸出,這裏是我的代碼:

% Load images 
f1 = (imread('f1.jpg')); 
f2 = (imread('f2.jpg')); 

%compute 2D FT of F1 and F2 

F1 = fft2(double(f1)); 
F2 = fft2(double(f2)); 

% Find magnitude and phase of the two images 

F1Mag = abs(F1); 
F1Phase = angle(F1); 

F2Mag = abs(F2); 
F2Phase = angle(F2); 

% set magnitudes to 1 

Gone = exp(1j*F1Phase); 
Gtwo = exp(1j*F2Phase); 

%invert to image 

gone = uint8(ifft2(Gone)); 
gtwo = uint8(ifft2(Gtwo)); 

我不知道我在做什麼錯了,任何幫助/建議將是驚人的。謝謝

+0

你爲什麼最終把它當作'uint8'? – Suever

+0

原始圖像在uint8中,所以爲了從反傅里葉圖像中取出圖像,我必須把它放回uint8中。無論如何,這部分不是問題,因爲即使我刪除那部分我仍然得到一個完全黑色的圖像 – Ghazal

+0

你如何形象化你的形象?是的,'uint8'將所有值都壓縮到'0',所以它至少是問題的一部分。 – Suever

回答

2

您正在將您的數據(包含負數以及數字< 1)轉換爲uint8,這將導致您的所有值都被設置爲0,從而產生黑色圖像。您想要將圖像保存爲double並使用imagesc來顯示結果。

f1 = imread('cameraman.tif'); 
F1 = fft2(f1); 

% Set the magnitude to 1 
G1 = exp(1j * angle(F1)); 

% Convert back to image domain and take the real component 
g1 = real(ifft2(G1)); 

% Display the result using imagesc so it's scaled 
imagesc(g1); 
colormap gray; 

enter image description here

如果你真的想要的輸出爲uint8,你要首先使用mat2gray標準化的圖像,然後之前255縮放鑄造它作爲一個uint8

g2 = uint8(mat2gray(g1) * 255); 
+0

哦,我的上帝!這非常感謝你 – Ghazal