필터 지우기
필터 지우기

Phase correlation of images (Alternative to cross-correlation)

조회 수: 26 (최근 30일)
Gucci
Gucci 2022년 4월 30일
답변: Mark Pratt 2023년 12월 22일
Hello, I have developed a code for phase correlation, and I am trying to run it for some images I have, to find where they match and the similarity between them. However I am getting a very strange result, instead of matching where the highest intensity is, it is showing me that the most similar area of the image is the bottom left corner...
I don't know what is wrong with the code, what can I do to fix it?
I have attached a sample file here
clear; close all; clc;
load('my_mat_file.mat');
template = im2gray(ims(:,:,1));
background = im2gray(ims(:,:,2));
%% calculate padding
bx = size(background, 2);
by = size(background, 1);
tx = size(template, 2); % used for bbox placement
ty = size(template, 1);
%% fft
%// - Compute the cross power spectrum
Ga = fft2(background);
Gb = fft2(template, by, bx);
c = real(ifft2((Ga.*conj(Gb))./abs(Ga.*conj(Gb))));
%% find peak correlation
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = find(c == max(c(:)));
figure; surf(c), shading flat; % plot correlation
%% display best match
hFig = figure;
hAx = axes;
%// New - no need to offset the coordinates anymore
%// xpeak and ypeak are already the top left corner of the matched window
position = [xpeak(1), ypeak(1), tx, ty];
imshow(background, 'Parent', hAx);
imrect(hAx, position);

답변 (1개)

Mark Pratt
Mark Pratt 2023년 12월 22일
You probably need fftshift.

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by