Matlab Template Matching mit FFT

Ich habe Probleme mit dem Template-Matching in der Fourier-Domain in Matlab. Hier sind meine Bilder (der Künstler ist RamalamaCreatures on DeviantArt):

Mein Ziel ist es, einen Begrenzungsrahmen um das Ohr des Opossums zu platzieren, wie in diesem Beispiel (wo ich mit normxcorr2 einen Vorlagenabgleich durchgeführt habe):

Hier ist der Matlab-Code, den ich verwende:

clear all; close all;

template = rgb2gray(imread('possum_ear.jpg'));
background = rgb2gray(imread('possum.jpg'));

%% calculate padding
bx = size(background, 2); 
by = size(background, 1);
tx = size(template, 2); % used for bbox placement
ty = size(template, 1);

%% fft
c = real(ifft2(fft2(background) .* fft2(template, by, bx)));

%% 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;
position = [xpeak(1)-tx, ypeak(1)-ty, tx, ty];
imshow(background, 'Parent', hAx);
imrect(hAx, position);

Der Code funktioniert nicht wie beabsichtigt - er identifiziert nicht die richtige Region. Dies ist das fehlerhafte Ergebnis - der falsche Bereich ist eingerahmt:

Dies ist das Flächendiagramm der Korrelationen für die fehlgeschlagene Übereinstimmung:

Hoffentlich können Sie helfen! Vielen Dank

Antworten auf die Frage(2)

Ihre Antwort auf die Frage