• 大小: 9KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 其他
  • 标签: B样条  

资源简介

B样条算法是对图像进行插值,其效果比一般的算法要好很多,此资源为源代码

资源截图

代码片段和文件信息

#include
#include
#include

#include
#include“bspline.h“

#pragma comment (lib“cv210.lib“)
#pragma comment (lib“cxcore210.lib“)
#pragma comment (lib“highgui210.lib“)

void B_SPLine::InitMouseControlPoint(char *windowNameIplImage *img)
{
cvZero(img);
m_MouseParam.img=img;
m_MouseParam.pclass=this;
cvSetMouseCallback(windowNameMouseCallback(void *)&m_MouseParam);
}

void B_SPLine::DrawBSPLine(IplImage *img)
{
int xy;
unsigned char *p;
float u;
std::list::iterator iter;

cvZero(img);
ControlPoint result;
for(iter=m_ControlPoints.begin();iter!=m_ControlPoints.end();++iter)
{
p=(unsigned char *)(img->imageData+iter->point.x*img->nChannels+iter->point.y*img->widthStep);
*p=255;
}

for(u=0;u<1.0;u+=0.002)
{
GetBSPLine(u&result);
p=(unsigned char *)(img->imageData+result.point.x*img->nChannels+result.point.y*img->widthStep);
*p=128;
}
}

void B_SPLine::GetURegion(float u)
{
int iN;
N=m_ControlPoints.size();
m_DeltaU=1.0/N;
m_LowerBoundIdx=(int)(u/m_DeltaU);
m_LowerBound=m_LowerBoundIdx*m_DeltaU;
m_UpperBound=m_DeltaU+m_LowerBound;
}

bool B_SPLine::GetBSPLine(float u ControlPoint *result)
{
int i;
float *pN;
float tmpxtmpy;

std::list::iterator iter;
//获取u所在区间
GetURegion(u);
//清零结果结构体中的所有变量值
tmpx=0;
tmpy=0;
//根据u更新所有有关的B样条基函数
CalcNiku(u);
//计算B样条曲线对应于u的值
i=(m_K+1)*m_K/2;
pN=m_Niku+i;

if(m_LowerBoundIdx>=m_K)
{
for(iter=m_ControlPoints.begin()i=0;i {
;
}
for(i=0;i<=m_K;++i++iter)
{
tmpx+=iter->point.x*pN[m_K-i];
tmpy+=iter->point.y*pN[m_K-i];
//printf(“(%f%f)-“tmpxtmpy);
}
}
else
{
pN=pN+m_K;
for(iter=m_ControlPoints.end()i=m_K-m_LowerBoundIdx;i>0;i--)
{
--iter;
}
for(;iter!=m_ControlPoints.end();++iter)
{
tmpx+=iter->point.x**pN;
tmpy+=iter->point.y**pN;
--pN;
}
for(iter=m_ControlPoints.begin()i=0;i<=m_LowerBoundIdx;++iter++i)
{
tmpx+=iter->point.x**pN;
tmpy+=iter->point.y**pN;
--pN;
}
}
result->point.x=tmpx;
result->point.y=tmpy;
//getchar();
return TRUE;
}

void B_SPLine::CalcNiku(float u)
{
int kl;
float *pN;
float tmp1tmp2;
int N;

N=m_ControlPoints.size();

pN=m_Niku;
*pN=1;
++pN;
for(k=1;k<=m_K;++k)
{
for(l=0;l<=k;++l)
{
if(l==0)
{
tmp1=GetNiku(0k-1);
*pN=(u-m_LowerBound)/k/m_DeltaU*tmp1;
}
else if(l==k)
{
tmp1=GetNiku(l-1k-1);
*pN=(m_UpperBound-u)/k/m_DeltaU*tmp1;
}
else
{
tmp1=GetNiku(lk-1);
tmp2=GetNiku(l-1k-1);
*pN=(u-m_LowerBound+l*m_DeltaU)*tmp1+(m_UpperBound+(k-l)*m_DeltaU-u)*tmp2;
tmp1=k*m_DeltaU;
*pN/=tmp1;
}
//printf(“l--%dk--%d%f\n“lk*pN);
//getchar();
++pN;
}
}
}


B_SPLine::B_SPLine(int k)
{
int tmp;
m_K=k;
tmp=(k+1)*(k+2)/2;
m_Niku=new float[tmp

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-03-22 19:40  B样条\
     文件        4072  2012-03-20 16:05  B样条\bspline.cpp
     文件        1459  2012-03-17 09:55  B样条\bspline.h
     文件        4022  2012-03-17 10:30  B样条\bspline.vcproj
     文件        1427  2012-03-20 17:00  B样条\bspline.vcproj.WWW-F94CB748A28.Administrator.user
     文件        6283  2012-03-20 16:53  B样条\bsplineinter.cpp
     文件         647  2012-03-20 16:21  B样条\bsplineinter.h
     文件        6032  2012-03-17 10:33  B样条\intFIFO.cpp
     文件         831  2012-03-17 10:33  B样条\intfifo.h
     文件        3125  2012-03-20 16:45  B样条\test.cpp

评论

共有 条评论