相位相关matlab实现

Here is working code for an example that uses a single image and cuts out a 256x256 pixel portion of the image from one location 

即在同一副图像中,先切一个256*256的图片,然后位移,再切一个同样大小256*256的图像

and then cuts out the same size portion from a location that has been translated by 11 pixels in the x direction and 7 pixels in the y direction. 

This shows that the basic technique does work when you have the code formatting correct.


image1 = rgb2gray(imread('frame429.jpg')); % read in image and convert from RGB ro grayscale
rect1 = [1 1 255 255]; % define first cutout region [xmin ymin width height]
rect2 = [12 8 255 255]; % define second translated cutout region [xmin ymin width height]
sub_image1 = imcrop(image1,rect1); % 1st cut out portion of original image 
sub_image2 = imcrop(image1,rect2); % 2nd cut out portion of original image 
filter1=blackman(length(sub_image1),'symmetric');
filtimg1=(filter1*filter1');
Image1=double(sub_image1).*filtimg1;
Image2=double(sub_image2).*filtimg1
FFT1 = fft2(Image1);
FFT2 = conj(fft2(Image2));
FFTR = FFT1.*FFT2;
magFFTR = abs(FFTR);
FFTRN = (FFTR./magFFTR);
result = ifft2(double(FFTRN)); 
figure;
colormap('gray'); % choose colormap for plotting
imagesc(result);
figure;
colormap(jet);

mesh(result);


The code can easily be changed to use two different images of the same dimensions:

image1 = rgb2gray(imread('castle_color1.tif')); % read image 1 (convert to grayscale if RGB)
image2 = rgb2gray(imread('castle_color5.tif')); % read image 2 must have same dimensions as image 1
subplot(1,2,1);imshow(image1);
subplot(1,2,2);imshow(image2);
filter1=blackman(size(image1,1),'symmetric'); % setup window in one direction - I chose Blackman window - could use Hamming or others
filter2=blackman(size(image1,2),'symmetric'); % setup window in second direction
filtimg1=(filter1*filter2'); % make 2D windowing function that is sized to match image
Image1=double(image1).*filtimg1; % apply windowing function to image
Image2=double(image2).*filtimg1;
FFT1 = fft2(Image1); % 2d FFT
FFT2 = conj(fft2(Image2)); 
FFTR = FFT1.*FFT2; % G1*G2复共轭
magFFTR = abs(FFTR); %sqrt(real^2 + imag^2) 幅值
FFTRN = (FFTR./magFFTR);
result = ifft2(double(FFTRN)); 
figure;
colormap('gray'); % choose colormap for plotting
imagesc(result);
figure;
colormap(jet);
mesh(result);


  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值