模板与图像相似性
发布时间:2020-12-14 02:19:18 所属栏目:大数据 来源:网络整理
导读:对两幅图像进行相似度的衡量,除了用眼睛观察的方法外,我们可以更加精确地用数据来客观的评估归一化,归一化的相关系数(NC)提供了度量工具。其计算公式如下: MATLAB代码如下所示: function dNC = nc(ImageA,ImageB)if (size(ImageA,1) ~= size(ImageB,1))
对两幅图像进行相似度的衡量,除了用眼睛观察的方法外,我们可以更加精确地用数据来客观的评估归一化,归一化的相关系数(NC)提供了度量工具。其计算公式如下: MATLAB代码如下所示:
function dNC = nc(ImageA,ImageB) if (size(ImageA,1) ~= size(ImageB,1)) | (size(ImageA,2) ~= size(ImageB,2)) error('ImageA <> ImageB'); dNC = 0; return ; end ImageA=double(ImageA); ImageB=double(ImageB); M = size(ImageA,1); N = size(ImageA,2); d1=0; d2=0; d3=0; for i = 1:M for j = 1:N d1=d1+ImageA(i,j)*ImageB(i,j) ; d2=d2+ImageA(i,j)*ImageA(i,j) ; d3=d3+ImageB(i,j) ; end end dNC=d1/(sqrt(d2)*sqrt(d3)); VC代码则根据自己所用库进行相应的修改,下面附上我自己所用的代码片段: int imgA_width; int imgA_height; int imgB_width; int imgB_height; imgA_width = m_img1_file.GetWidth(); imgA_height = m_img1_file.GetHeight(); imgB_width = m_img2_file.GetWidth(); imgB_height = m_img2_file.GetHeight(); if((imgA_width != imgB_width) || (imgA_height != imgB_height)) { AfxMessageBox(_T("输入图像大小不相等!")); return; } double d1=0.0; double d2=0.0; double d3=0.0; COLORREF colorA; COLORREF colorB; BYTE byteA; BYTE byteB; //相关系数计算 for(int i=0;i<imgA_height;i++) { for(int j=0;j<imgA_width;j++) { colorA = m_img1_file.GetPixel(j,i); colorB = m_img2_file.GetPixel(j,i); byteA = GetRValue(colorA); byteB = GetRValue(colorB); d1 = d1+byteA*byteB; d2 = d2+byteA*byteA; d3 = d3+byteB*byteB; } } m_ctNC = d1/(sqrt(d2)*sqrt(d3)); this->UpdateData(false); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |