2016-09-13 36 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