归一化互相关的基础 [英] Basics of normalized cross correlation

查看:321
本文介绍了归一化互相关的基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 normxcorr2 正常化互相关),用于计算发育中胚胎中运动形状的速度。我有3个问题:



1)我的图片大小为260x360像素。我给出一个10x10像素的模板大小,我要求命令在50x50像素的搜索窗口中的后续帧中搜索此模板。我得到一个大小为59x59的相关矩阵。因此,这意味着命令在搜索窗口内逐个像素地移动模板,寻找最佳相关性。对吗?



2)相关矩阵中的每个值表示搜索窗口中的模板矩阵。对吗?



3)假设我在相关矩阵中的第10行和第16列获得最大值。这意味着最佳相关模板位于图像中的y方向上的第10个矩阵和x方向上的第16个矩阵。

解决方案

为了说明 normxcorr2 的使用,请考虑以下示例href =http://www.mathworks.com/support/solutions/en/data/1-ABB9K9/index.html?product=IP&solution=1-ABB9K9 =nofollow noreferrer>此页< a>)

 %#在浅灰色背景上做浅灰色加上
template = 0.2 * ones(11)
template(6,3:9)= 0.6;
template(3:9,6)= 0.6;
BW = single(template> 0.5); %#在白色背景上使白色加上
imtool(template,'InitialMagnification','fit')

%#创建偏移模板的新图像
offsetTemplate = 0.2 * ones (81);
offset = [30 50]; %#Shift 30行50列
offsetTemplate(1:size(template,1))+ offset(1),...
(1:size(template,2))+ offset (2))= template;
imtool(offsetTemplate,'InitialMagnification',400)

%#交叉相关BW和offsetTemplate以恢复偏移
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('输入偏移:%d,%d \\\
Recovered偏移:%d,%d \\\
',偏移,corr_offset)
/ pre>

I am trying to use normxcorr2 (normalized cross-correlation) from MATLAB for calculating velocity of moving shapes in a developing embryo. I have 3 questions:

1) My image size is 260x360 pixels. I give a template size of 10x10 pixels and I ask the command to search for this template in the subsequent frame in a search window of 50x50 pixels. I get a correlation matrix of size 59x59. So this means that the command moves the template pixel by pixel within the search window looking for the best correlation. Right?

2) Each value in the correlation matrix represents a template matrix in the search window. Right?

3) Say I get a max at the 10th row and 16th column in the correlation matrix. This means that the best correlated template lies in the 10th matrix in the y direction and 16th matrix in the x direction in the image. Right?

解决方案

To illustrate the use of normxcorr2, consider the following example (adapted from 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)

这篇关于归一化互相关的基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆