我正在Matlab中的傅里叶域中进行模板匹配.这是我的图像(艺术家是DeviantArt上的RamalamaCreatures):
我的目标是在负鼠的耳朵周围放置一个边界框,就像这个例子(我使用normxcorr2执行模板匹配):
这是我正在使用的Matlab代码:
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, …Run Code Online (Sandbox Code Playgroud) matlab fft image-processing template-matching cross-correlation