归一化相关 matlab,matlab – 归一化互相关的基础知识

为了说明normxcorr2的使用,请考虑以下示例(改编自

this page)

%# Make light gray plus on dark gray background

template = 0.2*ones(11);

template(6,3:9) = 0.6;

template(3:9,6) = 0.6;

BW = single(template > 0.5); %# Make white plus on black background

imtool(template, 'InitialMagnification','fit')

%# Make new image that offsets the template

offsetTemplate = 0.2*ones(81);

offset = [30 50]; %# Shift by 30 rows, 50 columns

offsetTemplate( (1:size(template,1))+offset(1), ...

(1:size(template,2))+offset(2) ) = template;

imtool(offsetTemplate, 'InitialMagnification',400)

%# Cross-correlate BW and offsetTemplate to recover offset

cc_norm = normxcorr2(BW, offsetTemplate);

imtool(cc_norm, 'InitialMagnification',400)

[max_cc_norm, imax] = max( abs(cc_norm(:)) );

[ypeak, xpeak] = ind2sub(size(cc_norm), imax(1));

corr_offset = [ (ypeak-size(template,1)) (xpeak-size(template,2)) ];

fprintf('Input offset: %d,%d\nRecovered offset: %d,%d\n', offset, corr_offset)

你可能感兴趣的:(归一化相关,matlab)