可能我没等到8分钟吧,大神说的在理,受教;希望rjsp版主帮忙看下。
代码其实就是实现矩阵卷积(在循环中遍历相乘、求和,)
////////////为实现卷积计算,补齐数据,nmtf为卷积模版大小7*7,sample,line为图像行列7000*7000////////////
void MakeDataForCov(double *pInputData, double *pOutputData, int nmtf, int sample, int line)
{
int ns = sample+nmtf-1;
int nl = line+nmtf-1;
int margin = (nmtf-1)/2;
int i,j;
for (i=0; i<line; i++)
for (j=0; j<sample; j++)
*(pOutputData+(margin+i)*ns+margin+j) = *(pInputData+i*sample+j);
for (i=0; i<line; i++)//OutputData左右补齐
{
for (j=0; j<margin; j++)
{
*(pOutputData+(margin+i)*ns+j) = *(pInputData+i*sample+margin-j);
*(pOutputData+(margin+i)*ns+margin+sample+j) = *(pInputData+i*sample+sample-2-j);
}
}
for (i=0; i<margin; i++)//OutputData上下补齐
{
for (j=0; j<ns; j++)
{
*(pOutputData+(margin-1-i)*ns+j) = *(pOutputData+(i+margin)*ns+j);
*(pOutputData+(margin+line+i)*ns+j) = *(pOutputData+(margin+line-1-i)*ns+j);
}
}
}
///////////////////////////ImageConvol为计算图像卷积函数,pMakedata为上面补齐的输入图像,conv_template为卷积模版,大小为nPSFnum(7)*nPSFnum(7),conv_Image为输出/////
void ImageConvol(double *pMakedata,double *conv_template,int nPSFnum,double *conv_Image)
{
int nSample=7000;int nLine=7000;
for (int j=0;j<nSample;j++)
{
for (int k=0;k<nLine;k++)
{
float tmpData=0;
for (int m=0;m<nPSFnum;m++)
{
for (int n=0; n<nPSFnum;n++)
{
tmpData =tmpData+ *(pMakedata+(k+m)*(nSample+nPSFnum-1)+n+j) * *(conv_template+m*nPSFnum+n);
}
}
*(conv_Image+k*nSample+j) = (float)tmpData;
}
}
}