发布网友 发布时间:2022-04-23 22:42
共1个回答
热心网友 时间:2022-05-02 06:33
算法描述
procere ImageMatching
{
输入FirstImage;
输入SecondImage;
//获得两幅图象的大小
Height1=GetImageHeight(FirstImage);
Height2=GetImageHeight(SecondImage);
Width1=GetImageWidth(FirstImage);
Width2=GetImageWidth(SecondImage);
// 从第二幅图象取网格匹配模板
SecondImageGrid = GetSecondImageGrid(SecondImage);
// 粗略匹配,网格在第一幅图象中先从左向右移动,再从下到上移动,每次移动一个网格间距,Step_Width 或Step_Height,当网格移出重叠区域后结束
y=Heitht1-GridHeight;
MinValue = MaxInteger;
While ( y<Height1-OverlapNumber)//当网格移出重叠部分后结束
{
x=Grid_Width/2; //当网格位于第一幅图象的最左边时,A点的横坐标。
While ( x<(Width1-Grid_Width/2) )
{
FirstImageGrid=GetImgaeGrid(FirstImgaeGrid, x, y);
differ=CaculateDiff(FirstImgaeGrid, SecondImageGrid);//计算象素值差的平
//方和
if (differ<MinValue)
{
BestMatch_x=x;
BestMatch_y=y;
MinValue = differ;
}
x= x+Step_width;
}
y=y-Step_Height;
}
//精确匹配
Step_Width= Step_Width/2;
Step_Height= Step_Height/2;
While ( Step_Height>0 & Step_Width>0)//当水平步长和垂直步长均减为零时结束
{
if(Step_Height==0)//当仅有垂直步长减为零时,将其置为1
Step_Height=1;
If(Step_Width==0) //当仅有水平步长减为零时,将其置为1
Step_Width=1;
temp_x = BestMatch_x;
temp_y = BestMatch_y;
for ( i= -1; i<1; i++)
for( j= -1; j<1; j++)
{
if ((i=0&j!=0)|(i!=0&j=0))
{
FirstImageGrid=GetImgaeGrid(FirstImgaeGrid,
temp_x+i*Step_Width, temp_y +j*Step_Height);
differ=CaculateDiff(FirstImgaeGrid, SecondImageGrid);
if (differ<MinValue)
{
BestMatch_x=x;
BestMatch_y=y;
MinValue = differ;
}
}
}
Step_Height = Step_Height /2;
Step_Width = Step_Width/2;
}
}
不懂的可以问我,相互交流