如何在两个输入图像之间切换幅度和相位信息?

-4 c matlab image switching phase

我是一名正在攻读matlab的学生.

================================================== ================

[题]

切换两个输入图像之间的幅度和相位信息

加载两个不同的输入图像

比较切换给定输入的幅度和相位信息的结果.

================================================== ================

参考文献1:互联网用户

参考文献2:http://paeton.tistory.com/15

================================================== ================

我的答案 :

cm=imread('image1.bmp');
figure, imshow('image1.bmp');

cf=fftshift(fft2(cm));
g1=mat2gray(fspecial('gaussian',480,10));
cg1=cf.*g1;
figure,fftshow(cg1,'log');
cgi1=ifft2(cg1);
fftshow(cgi1,'abs');

cf=fftshift(fft2(cm));
g1=mat2gray(fspecial('gaussian',480,50));
cg1=cf.*g1;
figure,fftshow(cg1,'log');
cgi1=ifft2(cg1);
fftshow(cgi1,'abs');
Run Code Online (Sandbox Code Playgroud)

================================================== ================

我把答案提交给老师,但是错了.

从现在开始已有两个月,但不是每个人都可以给出答案.

我不知道如何解决这个问题.

请帮我.请转换源代码的相位和幅度.

Sha*_*hai 5

哦......我为你感到难过.
你应该自己回答你的作业问题!

function I_must_understand_this_code_before_I_submit_my_homework( )

% read images
im{1} = im2double( imread( 'image1.bmp' ) );
im{2} = im2double( imread( 'image2.bmp' ) );
assert( all( size(im{1}) == size(im{2}) ), 'images must have same size' );

% FFT - separate magnitude and phase no fftshift
mag = cell(1,2);
phz = cell(1,2);
for ii=1:2
    I = zeros( size(im{ii}) );
    for c = 1:size(im{ii},3) % for color images
        I(:,:,c) = fft2( im{ii}(:,:,c) );
    end
    mag{ii} = abs( I ); % magnitude of fft
    phz{ii} = angle( I ); % phase
end

% combine (still in Fourier domain)
C{1} = mag{1}.*exp( j * phz{2} ); % mag of first with phase of second
C{2} = mag{2}.*exp( j * phz{1} ); % mag of second with phase of first

% back to image domain
comb = cell(1,2);
for ii=1:2
    for c = 1:size(C{ii},3)
        comb{ii}(:,:,c) = ifft2( C{ii}(:,:,c) )
    end
    comb{ii} = abs(comb{ii}); % discard imaginary part
end
% dispaly
figure('Name','I should forever be grateful to stack overflow!');
subplot(221);
imshow( im{1} ); title('image1');
subplot(222);
imshow( im{2} ); title('image2');
subplot(223);
imshow( comb{1} ); title('mag of 1 with phase of 2');    
subplot(224);
imshow( comb{2} ); title('mag of 2 with phase of 1');    
Run Code Online (Sandbox Code Playgroud)

  • @Elesis请注意,stackoverflow(SO)通常**不是**为你做功课.我为你感到难过所以我发布了这个解决方案.为了让我对自己的所作所为感到满意,如果你仔细研究这个解决方案并且实际上从中学到关于matlab和图像处理的**,我将不胜感激.你能解释为什么组合图像看起来像它们的样子吗? (3认同)