フィルターのクリア

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 件のコメント
Gucci
Gucci 2022 年 4 月 30 日
編集済み: Gucci 2022 年 4 月 30 日
@Walter Roberson any idea on this method?

サインインしてコメントする。

回答 (1 件)

Mark Pratt
Mark Pratt 2023 年 12 月 22 日
You probably need fftshift.

カテゴリ

Help Center および File ExchangeDiscrete 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