zoukankan      html  css  js  c++  java
  • 20190710记录2:插值图像拼接融合记录

    6、对图像拼接边界进行过渡处理。向内收进去25像素的圈,两图各占50%。

    // Imagejoint.cpp : 定义控制台应用程序的入口点。
    //
    #include "stdafx.h"
    #include "Imagejoint.h"
    #include <afxwin.h> 
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    #include <atlimage.h>//CImage类
    #include <locale.h>
    #include "math.h"
    using namespace std;
    //双三次插值系数
    double fs(double w)
    {    
            double a=-0.5;
            double fs;
            if (abs(w)<=1)
                fs=(a+2)*pow(abs(w),3)-(a+3)*pow(abs(w),2)+1;
            else if (abs(w)>1&&abs(w)<=2)
                fs=a*pow(abs(w),3)-5*a*pow(abs(w),2)+8*a*abs(w)-4*a;
            else
                fs=0;
            return fs;
    }
    
    HRESULT Imagejoint(PBYTE pbSrc1,PBYTE pbSrc2,int iWidth,int iHeight,double dbZoom,PBYTE pbFinal);
    
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    
        int nRetCode = 0;//表示整数类型的函数返回码。n表示整数类型,Ret是Return的缩写,表示返回值,Code表示代码。
        setlocale(LC_ALL,"chs");
        HMODULE hModule = ::GetModuleHandle(NULL);
    
        if (hModule != NULL)
        {
    
            HRESULT hResult1,hResult2;
            //初始化一些变量
            int        iWidth,iHeight,iBytePerPixel,iPitch;
            int        x,y;
            PBYTE    pbSrc1=NULL,pbSrc2=NULL,pbFinal=NULL;//源图、目标图
            PBYTE    pbImage=NULL;//load图像后存在这
            PDWORD    pdwImage=NULL;//用于保存图像
            double    dbZoom=1.25;
    
            for(dbZoom=1.25;dbZoom<=2.25;dbZoom+=0.25)
            {
                CImage cImage_far;
                CImage cImage_near;
        
                CString str = "far-frame1.bmp";
                CString str2 = "near-frame1.bmp";
                LPCTSTR filename1 = (LPCTSTR)str;
                LPCTSTR filename2 = (LPCTSTR)str2;
      
                if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
                {
                    // TODO: change error code to suit your needs
                    _tprintf(_T("Fatal Error: MFC initialization failed
    "));
                    nRetCode = 1;
                    
                }
                //Load 图像到cImage对象中
                hResult1=cImage_far.Load(filename1);
                hResult2=cImage_near.Load(filename2);
                if(hResult1!=ERROR_SUCCESS||hResult2!=ERROR_SUCCESS)
                {
                    _tprintf(_T("源图像文件名错误!
    "));
                    nRetCode= -3;
                  
                }
                
                iWidth=cImage_far.GetWidth();
                iHeight=cImage_far.GetHeight();
                //分配源图内存
                pbSrc1 = (PBYTE)malloc(iWidth*iHeight);
                pbSrc2 = (PBYTE)malloc(iWidth*iHeight);
                //分配目标图内存
                pbFinal = (PBYTE)malloc(1280*1024);
                if(pbSrc1==NULL||pbSrc2==NULL || pbFinal==NULL )
                {
                    _tprintf(_T("内存申请错误!
    "));
                    nRetCode= -4;
                   
                }
                //cImage数据存到pbImage,后再转换为源灰度图pbSrc
                iPitch=cImage_far.GetPitch();
                iBytePerPixel=(cImage_far.GetBPP()+7)/8;
                if(iBytePerPixel==3)
                {
                    for(y=0;y<iHeight;y++)
                    {   //load的图像数据放到pbImage
                        pbImage=(PBYTE)(PBYTE(cImage_far.GetBits())+iPitch*y);//得到的是图像初始像素地址
                        for(x=0;x<iWidth;x++)
                        {
                            //pbImage转换为灰度图pbSrc
                            pbSrc1[y*iWidth+x]=(pbImage[3*x]*0.15+pbImage[3*x+1]*0.55+pbImage[3*x+2]*0.3);
                        }
                    }
                }
                cImage_far.Destroy();
    
                iPitch=cImage_near.GetPitch();
                iBytePerPixel=(cImage_near.GetBPP()+7)/8;
                if(iBytePerPixel==3)
                {
                    for(y=0;y<iHeight;y++)
                    {   //load的图像数据放到pbImage
                        pbImage=(PBYTE)(PBYTE(cImage_near.GetBits())+iPitch*y);//得到的是图像初始像素地址
                        for(x=0;x<iWidth;x++)
                        {
                            //pbImage转换为灰度图pbSrc
                            pbSrc2[y*iWidth+x]=(pbImage[3*x]*0.15+pbImage[3*x+1]*0.55+pbImage[3*x+2]*0.3);
                        }
                    }
                }
                cImage_near.Destroy();
    
                //执行操作
                hResult1=Imagejoint(pbSrc1,pbSrc2,iWidth,iHeight,dbZoom,pbFinal);
                if(hResult1!=ERROR_SUCCESS)
                {
                    _tprintf(_T("图像处理错误!
    "));
                    nRetCode= -5;
                   
                }
                //处理后保存图像
                iWidth=1280;
                iHeight=1024;
                cImage_far.Create(iWidth,-iHeight,32);
                iPitch=cImage_far.GetPitch();
                for(y=0;y<iHeight;y++)
                {
                    pdwImage=(PDWORD)(PBYTE(cImage_far.GetBits())+iPitch*y);
                    for(x=0;x<iWidth;x++)
                    {
                        pdwImage[x]=pbFinal[y*iWidth+x]*0x10101;  
                    }
                }
                //可预存待保存图像文件名
                CString name1="target";
                CString name2;
                name2.Format(_T("%.2lf"),dbZoom);
                CString csTagName;
                csTagName=name1+name2;
                
                csTagName.Trim();
                csTagName.MakeUpper();
                if(csTagName.Right(4)!=_T(".BMP") ) csTagName.Append(_T(".BMP"));
                hResult1=cImage_far.Save(csTagName);
                if(hResult1!=ERROR_SUCCESS)
                {
                    _tprintf(_T("图像结果保存错误!
    "));
                    nRetCode= -5;
                   
                }
                _tprintf(_T("图像处理成功!
    "));
                nRetCode= ERROR_SUCCESS;
    
                if(pbSrc1) free(pbSrc1);
                if(pbSrc2) free(pbSrc2);
                if(pbFinal) free(pbFinal);
            }//对应+=0.25倍数的for循环。
    
        }
        else
        {
            _tprintf(_T("Fatal Error: GetModuleHandle failed
    "));
            nRetCode = 1;
        }
        getchar();    
        return nRetCode;
    }
    
    HRESULT Imagejoint(PBYTE pbSrc1,PBYTE pbSrc2,int iWidth,int iHeight,double dbZoom,PBYTE pbFinal)
    {
        double phase[33]={0};//16相位,包含端点存在33个距离
        for (int i=0;i<33;i++)
        {
            double i2=1.0*i;
            phase[i]=fs(i2/16);
        }
    
        //旋转中心为图像中心
        double rx0=iWidth;  
        double ry0=iHeight; 
        double srcx,srcy,u,v;
        int xOr,yOr;
        int newWidth=ceil(dbZoom*iWidth);
        int newHeight=ceil(dbZoom*iHeight);
    
        for (int y=0;y<1024;y++)
        {
            for (int x=0;x<1280;x++)
            {
    
                srcx=(double)(newWidth/2-640+x)/dbZoom;
                srcy=(double)(newHeight/2-512+y)/dbZoom ;
                xOr = floor(srcx);
                yOr = floor(srcy);
                u=srcx-xOr;
                v=srcy-yOr;
    
                int phasex=floor(16*u+0.5);//16相位
                int phasey=floor(16*v+0.5);
                double A1,B1,C1,D1,A2,B2,C2,D2;
                A1=phase[16+phasex];
                B1=phase[phasex];
                C1=phase[16-phasex];
                D1=phase[32-phasex];
    
                A2=phase[16+phasey];
                B2=phase[phasey];
                C2=phase[16-phasey];
                D2=phase[32-phasey];
    
                //Matlab中测试获取定值(34:541 -Y,41:728 -X),需要微调。
                if( !(srcx>=41 && srcx<=720 && srcy>=34 && srcy<=541))//越界部分需拼接为外圈大视场图像,远景
                    {
                        srcx=(double)(newWidth-640+x)/(2*dbZoom)+6;//补偏差
                        srcy=(double)(newHeight-512+y)/(2*dbZoom)-3;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr; 
                        v=srcy-yOr;
    
                        phasex=floor(16*u+0.5);//16相位
                         phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
    
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];
    
                        double middle=
                        pbSrc1[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc1[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc1[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc1[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle<=255&&middle>=0)
                        pbFinal[y*1280+x]=middle;
                    else if(middle>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;}
    
                else if( !(srcx>=66 && srcx<=695 && srcy>=59 && srcy<=516))
                        {
                            //pbFinal[y*1280+x]=255;
    
                        srcx=(double)(newWidth-640+x)/(2*dbZoom)+6;//补偏差
                        srcy=(double)(newHeight-512+y)/(2*dbZoom)-3;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr; 
                        v=srcy-yOr;
                        phasex=floor(16*u+0.5);//16相位
                        phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];
    
                        double middle1=
                        pbSrc1[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr-1)]*A1*D2+                    
                        pbSrc1[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr)]*B1*D2+
                        pbSrc1[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
                        pbSrc1[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
                //------------------------------------------------------------
                        srcx=(double)(newWidth/2-640+x)/dbZoom;
                        srcy=(double)(newHeight/2-512+y)/dbZoom ;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr;
                        v=srcy-yOr;
                        phasex=floor(16*u+0.5);//16相位
                        phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];            
                        double middle2=
                        pbSrc2[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr-1)]*A1*D2+                    
                        pbSrc2[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr)]*B1*D2+
                        pbSrc2[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
                        pbSrc2[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    //边界融合
                    double middle3=0.5*middle1+0.5*middle2;
    
                    if(middle3<=255&&middle3>=0)
                        pbFinal[y*1280+x]=middle3;
                    else if(middle3>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;
                                            
                        } 
                else
                {   
                    double middle3=
                        pbSrc2[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc2[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc2[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc2[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle3<=255&&middle3>=0)
                        pbFinal[y*1280+x]=middle3;
                    else if(middle3>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;
                }
            }
        }
        return ERROR_SUCCESS;
    }
    View Code

    7、优化,对中间一圈设定范围,由外至内渐变。过渡25个像素,每像素渐变比例4%,0.04。

                            double weight=1;//代表内圈所占的权重
                            if(srcx>=41 && srcx<=66)
                                weight=(srcx-41)*0.04;
                            else if(srcx>=695 && srcx<=720)
                                weight=(720-srcx)*0.04;
    
                            if(srcy>=34 && srcy<=59)
                                weight=(srcy-34)*0.04;
                            else if(srcy>=516 && srcy<=541)
                                weight=(541-srcy)*0.04;
    
                            if((srcx>=41 && srcx<=66)&&(srcy>=34 && srcy<=59))
                                weight=(srcx-41)*0.02+(srcy-34)*0.02;
                            else if((srcx>=41 && srcx<=66)&&(srcy>=516 && srcy<=541))
                                weight=(srcx-41)*0.02+(541-srcy)*0.02;
                            else if((srcx>=695 && srcx<=720)&&(srcy>=34 && srcy<=59))
                                weight=(720-srcx)*0.02+(srcy-34)*0.02;
                            else if((srcx>=695 && srcx<=720)&&(srcy>=516 && srcy<=541))
                                weight=(720-srcx)*0.02+(541-srcy)*0.02;

    但是这种情况,四边还可以,四角会有点明显。

    考虑对于四角区域,取距离max。测试后max不行,应该取min。

    8、将渐变距离25设置为变量,transition[trænˈzɪʃn] 过渡。

    同时将外圈四点距离设为变量,确定下来。均为经验定值。int xl=41,xr=720,yu=34,yd=541;

    // Imagejoint.cpp : 定义控制台应用程序的入口点。
    //
    #include "stdafx.h"
    #include "Imagejoint.h"
    #include <afxwin.h> 
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    #include <atlimage.h>//CImage类
    #include <locale.h>
    #include "math.h"
    using namespace std;
    //双三次插值系数
    double fs(double w)
    {    
            double a=-0.5;
            double fs;
            if (abs(w)<=1)
                fs=(a+2)*pow(abs(w),3)-(a+3)*pow(abs(w),2)+1;
            else if (abs(w)>1&&abs(w)<=2)
                fs=a*pow(abs(w),3)-5*a*pow(abs(w),2)+8*a*abs(w)-4*a;
            else
                fs=0;
            return fs;
    }
    
    HRESULT Imagejoint(PBYTE pbSrc1,PBYTE pbSrc2,int iWidth,int iHeight,double dbZoom,PBYTE pbFinal);
    
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    
        int nRetCode = 0;//表示整数类型的函数返回码。n表示整数类型,Ret是Return的缩写,表示返回值,Code表示代码。
        setlocale(LC_ALL,"chs");
        HMODULE hModule = ::GetModuleHandle(NULL);
    
        if (hModule != NULL)
        {
    
            HRESULT hResult1,hResult2;
            //初始化一些变量
            int        iWidth,iHeight,iBytePerPixel,iPitch;
            int        x,y;
            PBYTE    pbSrc1=NULL,pbSrc2=NULL,pbFinal=NULL;//源图、目标图
            PBYTE    pbImage=NULL;//load图像后存在这
            PDWORD    pdwImage=NULL;//用于保存图像
            double    dbZoom=1.25;
    
            for(dbZoom=1.25;dbZoom<=2.25;dbZoom+=0.25)
            {
                CImage cImage_far;
                CImage cImage_near;
        
                CString str = "far-frame1.bmp";
                CString str2 = "near-frame1.bmp";
                LPCTSTR filename1 = (LPCTSTR)str;
                LPCTSTR filename2 = (LPCTSTR)str2;
      
                if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
                {
                    // TODO: change error code to suit your needs
                    _tprintf(_T("Fatal Error: MFC initialization failed
    "));
                    nRetCode = 1;
                    
                }
                //Load 图像到cImage对象中
                hResult1=cImage_far.Load(filename1);
                hResult2=cImage_near.Load(filename2);
                if(hResult1!=ERROR_SUCCESS||hResult2!=ERROR_SUCCESS)
                {
                    _tprintf(_T("源图像文件名错误!
    "));
                    nRetCode= -3;
                  
                }
                
                iWidth=cImage_far.GetWidth();
                iHeight=cImage_far.GetHeight();
                //分配源图内存
                pbSrc1 = (PBYTE)malloc(iWidth*iHeight);
                pbSrc2 = (PBYTE)malloc(iWidth*iHeight);
                //分配目标图内存
                pbFinal = (PBYTE)malloc(1280*1024);
                if(pbSrc1==NULL||pbSrc2==NULL || pbFinal==NULL )
                {
                    _tprintf(_T("内存申请错误!
    "));
                    nRetCode= -4;
                   
                }
                //cImage数据存到pbImage,后再转换为源灰度图pbSrc
                iPitch=cImage_far.GetPitch();
                iBytePerPixel=(cImage_far.GetBPP()+7)/8;
                if(iBytePerPixel==3)
                {
                    for(y=0;y<iHeight;y++)
                    {   //load的图像数据放到pbImage
                        pbImage=(PBYTE)(PBYTE(cImage_far.GetBits())+iPitch*y);//得到的是图像初始像素地址
                        for(x=0;x<iWidth;x++)
                        {
                            //pbImage转换为灰度图pbSrc
                            pbSrc1[y*iWidth+x]=(pbImage[3*x]*0.15+pbImage[3*x+1]*0.55+pbImage[3*x+2]*0.3);
                        }
                    }
                }
                cImage_far.Destroy();
    
                iPitch=cImage_near.GetPitch();
                iBytePerPixel=(cImage_near.GetBPP()+7)/8;
                if(iBytePerPixel==3)
                {
                    for(y=0;y<iHeight;y++)
                    {   //load的图像数据放到pbImage
                        pbImage=(PBYTE)(PBYTE(cImage_near.GetBits())+iPitch*y);//得到的是图像初始像素地址
                        for(x=0;x<iWidth;x++)
                        {
                            //pbImage转换为灰度图pbSrc
                            pbSrc2[y*iWidth+x]=(pbImage[3*x]*0.15+pbImage[3*x+1]*0.55+pbImage[3*x+2]*0.3);
                        }
                    }
                }
                cImage_near.Destroy();
    
                //执行操作
                hResult1=Imagejoint(pbSrc1,pbSrc2,iWidth,iHeight,dbZoom,pbFinal);
                if(hResult1!=ERROR_SUCCESS)
                {
                    _tprintf(_T("图像处理错误!
    "));
                    nRetCode= -5;
                   
                }
                //处理后保存图像
                iWidth=1280;
                iHeight=1024;
                cImage_far.Create(iWidth,-iHeight,32);
                iPitch=cImage_far.GetPitch();
                for(y=0;y<iHeight;y++)
                {
                    pdwImage=(PDWORD)(PBYTE(cImage_far.GetBits())+iPitch*y);
                    for(x=0;x<iWidth;x++)
                    {
                        pdwImage[x]=pbFinal[y*iWidth+x]*0x10101;  
                    }
                }
                //可预存待保存图像文件名
                CString name1="target";
                CString name2;
                name2.Format(_T("%.2lf"),dbZoom);
                CString csTagName;
                csTagName=name1+name2;
                
                csTagName.Trim();
                csTagName.MakeUpper();
                if(csTagName.Right(4)!=_T(".BMP") ) csTagName.Append(_T(".BMP"));
                hResult1=cImage_far.Save(csTagName);
                if(hResult1!=ERROR_SUCCESS)
                {
                    _tprintf(_T("图像结果保存错误!
    "));
                    nRetCode= -5;
                   
                }
                _tprintf(_T("图像处理成功!
    "));
                nRetCode= ERROR_SUCCESS;
    
                if(pbSrc1) free(pbSrc1);
                if(pbSrc2) free(pbSrc2);
                if(pbFinal) free(pbFinal);
            }//对应+=0.25倍数的for循环。
    
        }
        else
        {
            _tprintf(_T("Fatal Error: GetModuleHandle failed
    "));
            nRetCode = 1;
        }
        getchar();    
        return nRetCode;
    }
    
    HRESULT Imagejoint(PBYTE pbSrc1,PBYTE pbSrc2,int iWidth,int iHeight,double dbZoom,PBYTE pbFinal)
    {
        double phase[33]={0};//16相位,包含端点存在33个距离
        for (int i=0;i<33;i++)
        {
            double i2=1.0*i;
            phase[i]=fs(i2/16);
        }
    
        //旋转中心为图像中心
        double rx0=iWidth;  
        double ry0=iHeight; 
        double srcx,srcy,u,v;
        int xOr,yOr;
        int newWidth=ceil(dbZoom*iWidth);
        int newHeight=ceil(dbZoom*iHeight);
    
        for (int y=0;y<1024;y++)
        {
            for (int x=0;x<1280;x++)
            {
    
                srcx=(double)(newWidth/2-640+x)/dbZoom;
                srcy=(double)(newHeight/2-512+y)/dbZoom ;
                xOr = floor(srcx);
                yOr = floor(srcy);
                u=srcx-xOr;
                v=srcy-yOr;
    
                int phasex=floor(16*u+0.5);//16相位
                int phasey=floor(16*v+0.5);
                double A1,B1,C1,D1,A2,B2,C2,D2;
                A1=phase[16+phasex];
                B1=phase[phasex];
                C1=phase[16-phasex];
                D1=phase[32-phasex];
    
                A2=phase[16+phasey];
                B2=phase[phasey];
                C2=phase[16-phasey];
                D2=phase[32-phasey];
    
                //Matlab中测试获取定值(34:541 -Y,41:728 -X),需要微调。
                int xl=41,xr=720,yu=34,yd=541;
                int transition=25;//100的时候渐变还可以
    
    
                if( !(srcx>=xl && srcx<=xr && srcy>=yu && srcy<=yd))//越界部分需拼接为外圈大视场图像,远景
                    {
                        srcx=(double)(newWidth-640+x)/(2*dbZoom)+6;//补偏差
                        srcy=(double)(newHeight-512+y)/(2*dbZoom)-3;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr; 
                        v=srcy-yOr;
    
                        phasex=floor(16*u+0.5);//16相位
                         phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
    
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];
    
                        double middle=
                        pbSrc1[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc1[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc1[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc1[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle<=255&&middle>=0)
                        pbFinal[y*1280+x]=middle;
                    else if(middle>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;}
    
                else if( !(srcx>=xl+transition && srcx<=xr-transition && srcy>=yu+transition && srcy<=yd-transition))
                        {
                            double weight=1;//代表内圈所占的权重
                            if(srcx>=xl && srcx<=xl+transition)
                                weight=(srcx-xl)*1.0/transition;
                            else if(srcx>=xr-transition && srcx<=xr)
                                weight=(xr-srcx)*1.0/transition;
    
                            if(srcy>=yu && srcy<=yu+transition)
                                weight=(srcy-yu)*1.0/transition;
                            else if(srcy>=yd-transition && srcy<=yd)
                                weight=(yd-srcy)*1.0/transition;
    
                            if((srcx>=xl && srcx<=xl+transition)&&(srcy>=yu && srcy<=yu+transition))
                                weight=min((srcx-xl),(srcy-yu))*1.0/transition;
                            else if((srcx>=xl && srcx<=xl+transition)&&(srcy>=yd-transition && srcy<=yd))
                                weight=min((srcx-xl),(yd-srcy))*1.0/transition;
                            else if((srcx>=xr-transition && srcx<=xr)&&(srcy>=yu && srcy<=yu+transition))
                                weight=min((xr-srcx),(srcy-yu))*1.0/transition;
                            else if((srcx>=xr-transition && srcx<=xr)&&(srcy>=yd-transition && srcy<=yd))
                                weight=min((xr-srcx),(yd-srcy))*1.0/transition;
                            //pbFinal[y*1280+x]=255;
    
                        srcx=(double)(newWidth-640+x)/(2*dbZoom)+6;//补偏差
                        srcy=(double)(newHeight-512+y)/(2*dbZoom)-3;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr; 
                        v=srcy-yOr;
                        phasex=floor(16*u+0.5);//16相位
                        phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];
    
                        double middle1=
                        pbSrc1[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr-1)]*A1*D2+                    
                        pbSrc1[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr)]*B1*D2+
                        pbSrc1[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
                        pbSrc1[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
                //------------------------------------------------------------
                        srcx=(double)(newWidth/2-640+x)/dbZoom;
                        srcy=(double)(newHeight/2-512+y)/dbZoom ;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr;
                        v=srcy-yOr;
                        phasex=floor(16*u+0.5);//16相位
                        phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];            
                        double middle2=
                        pbSrc2[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr-1)]*A1*D2+                    
                        pbSrc2[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr)]*B1*D2+
                        pbSrc2[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
                        pbSrc2[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    //边界融合
                    double middle3=(1-weight)*middle1+weight*middle2;
    
                    if(middle3<=255&&middle3>=0)
                        pbFinal[y*1280+x]=middle3;
                    else if(middle3>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;
                                            
                        } 
    //内圈,核心区域
                else
                {   
                    double middle3=
                        pbSrc2[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc2[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc2[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc2[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle3<=255&&middle3>=0)
                        pbFinal[y*1280+x]=middle3;
                    else if(middle3>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;
                }
            }
        }
        return ERROR_SUCCESS;
    }
    View Code

    9、测试:

    transition=25时,效果一般;

    transition=50时,效果变好一点;

    transition=100时,效果很可以。

    10、遍历文件夹内图像,进行批量处理,先将文件名设为帧数变量,frame,。

                int frame=1;
                CImage cImage_far;
                CImage cImage_near;
                CString farsrc;
                CString nearsrc;
                CString str_far= "D:/文件及下载相关/桌面/XXX/Matlab_code/farframe/";
                CString str_near = "D:/文件及下载相关/桌面/XXX/Matlab_code/nearframe/";
                CString frame_num;
                frame_num.Format(_T("%d"),frame);
                farsrc=str_far+frame_num;
                nearsrc=str_near+frame_num;
                farsrc.Append(_T(".bmp"));
                nearsrc.Append(_T(".bmp"));
    
                LPCTSTR filename1 = (LPCTSTR)farsrc;
                LPCTSTR filename2 = (LPCTSTR)nearsrc;

    随后设置循环,dbZoom+=0.01;

    11、终版可演示(无亮度平衡)

    for(int frame=1;frame<=141;frame++)

    dbZoom+=0.007;

    int transition=100;

    // Imagejoint.cpp : 定义控制台应用程序的入口点。
    //
    #include "stdafx.h"
    #include "Imagejoint.h"
    #include <afxwin.h> 
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    #include <atlimage.h>//CImage类
    #include <locale.h>
    #include "math.h"
    using namespace std;
    //双三次插值系数
    double fs(double w)
    {    
            double a=-0.5;
            double fs;
            if (abs(w)<=1)
                fs=(a+2)*pow(abs(w),3)-(a+3)*pow(abs(w),2)+1;
            else if (abs(w)>1&&abs(w)<=2)
                fs=a*pow(abs(w),3)-5*a*pow(abs(w),2)+8*a*abs(w)-4*a;
            else
                fs=0;
            return fs;
    }
    
    HRESULT Imagejoint(PBYTE pbSrc1,PBYTE pbSrc2,int iWidth,int iHeight,double dbZoom,PBYTE pbFinal);
    
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    
        int nRetCode = 0;//表示整数类型的函数返回码。n表示整数类型,Ret是Return的缩写,表示返回值,Code表示代码。
        setlocale(LC_ALL,"chs");
        HMODULE hModule = ::GetModuleHandle(NULL);
    
        if (hModule != NULL)
        {
    
            HRESULT hResult1,hResult2;
            //初始化一些变量
            int        iWidth,iHeight,iBytePerPixel,iPitch;
            int        x,y;
            PBYTE    pbSrc1=NULL,pbSrc2=NULL,pbFinal=NULL;//源图、目标图
            PBYTE    pbImage=NULL;//load图像后存在这
            PDWORD    pdwImage=NULL;//用于保存图像
            double    dbZoom=1.00;
    
            //for(dbZoom=1.25;dbZoom<=2.25;dbZoom+=0.25)
            for(int frame=1;frame<=141;frame++)
            {
                //int frame=1;
                CImage cImage_far;
                CImage cImage_near;
                CString farsrc;
                CString nearsrc;
                CString str_far= "D:/文件及下载相关/桌面/模拟变焦拼接/Matlab_code/farframe/";
                CString str_near = "D:/文件及下载相关/桌面/模拟变焦拼接/Matlab_code/nearframe/";
                CString frame_num;
                frame_num.Format(_T("%d"),frame);
                farsrc=str_far+frame_num;
                nearsrc=str_near+frame_num;
                farsrc.Append(_T(".bmp"));
                nearsrc.Append(_T(".bmp"));
    
                LPCTSTR filename1 = (LPCTSTR)farsrc;
                LPCTSTR filename2 = (LPCTSTR)nearsrc;
      
                if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
                {
                    // TODO: change error code to suit your needs
                    _tprintf(_T("Fatal Error: MFC initialization failed
    "));
                    nRetCode = 1;
                    
                }
                //Load 图像到cImage对象中
                hResult1=cImage_far.Load(filename1);
                hResult2=cImage_near.Load(filename2);
                if(hResult1!=ERROR_SUCCESS||hResult2!=ERROR_SUCCESS)
                {
                    _tprintf(_T("源图像文件名错误!
    "));
                    nRetCode= -3;
                  
                }
                
                iWidth=cImage_far.GetWidth();
                iHeight=cImage_far.GetHeight();
                //分配源图内存
                pbSrc1 = (PBYTE)malloc(iWidth*iHeight);
                pbSrc2 = (PBYTE)malloc(iWidth*iHeight);
                //分配目标图内存
                pbFinal = (PBYTE)malloc(1280*1024);
                if(pbSrc1==NULL||pbSrc2==NULL || pbFinal==NULL )
                {
                    _tprintf(_T("内存申请错误!
    "));
                    nRetCode= -4;
                   
                }
                //cImage数据存到pbImage,后再转换为源灰度图pbSrc
                iPitch=cImage_far.GetPitch();
                iBytePerPixel=(cImage_far.GetBPP()+7)/8;
                if(iBytePerPixel==3)
                {
                    for(y=0;y<iHeight;y++)
                    {   //load的图像数据放到pbImage
                        pbImage=(PBYTE)(PBYTE(cImage_far.GetBits())+iPitch*y);//得到的是图像初始像素地址
                        for(x=0;x<iWidth;x++)
                        {
                            //pbImage转换为灰度图pbSrc
                            pbSrc1[y*iWidth+x]=(pbImage[3*x]*0.15+pbImage[3*x+1]*0.55+pbImage[3*x+2]*0.3);
                        }
                    }
                }
                cImage_far.Destroy();
    
                iPitch=cImage_near.GetPitch();
                iBytePerPixel=(cImage_near.GetBPP()+7)/8;
                if(iBytePerPixel==3)
                {
                    for(y=0;y<iHeight;y++)
                    {   //load的图像数据放到pbImage
                        pbImage=(PBYTE)(PBYTE(cImage_near.GetBits())+iPitch*y);//得到的是图像初始像素地址
                        for(x=0;x<iWidth;x++)
                        {
                            //pbImage转换为灰度图pbSrc
                            pbSrc2[y*iWidth+x]=(pbImage[3*x]*0.15+pbImage[3*x+1]*0.55+pbImage[3*x+2]*0.3);
                        }
                    }
                }
                cImage_near.Destroy();
    
                //执行操作
                hResult1=Imagejoint(pbSrc1,pbSrc2,iWidth,iHeight,dbZoom,pbFinal);
                if(hResult1!=ERROR_SUCCESS)
                {
                    _tprintf(_T("图像处理错误!
    "));
                    nRetCode= -5;
                   
                }
                //处理后保存图像
                iWidth=1280;
                iHeight=1024;
                cImage_far.Create(iWidth,-iHeight,32);
                iPitch=cImage_far.GetPitch();
                for(y=0;y<iHeight;y++)
                {
                    pdwImage=(PDWORD)(PBYTE(cImage_far.GetBits())+iPitch*y);
                    for(x=0;x<iWidth;x++)
                    {
                        pdwImage[x]=pbFinal[y*iWidth+x]*0x10101;  
                    }
                }
                //可预存待保存图像文件名
                CString name1="D:/文件及下载相关/桌面/模拟变焦拼接/Matlab_code/result/";
                CString name2;
                //这里要随着帧数改动
                name2.Format(_T("%d"),frame);
                CString csTagName;
                csTagName=name1+name2;
                
                csTagName.Trim();
                csTagName.MakeUpper();
                if(csTagName.Right(4)!=_T(".bmp") ) csTagName.Append(_T(".bmp"));
                hResult1=cImage_far.Save(csTagName);
                if(hResult1!=ERROR_SUCCESS)
                {
                    _tprintf(_T("图像结果保存错误!
    "));
                    nRetCode= -5;
                   
                }
                _tprintf(_T("图像处理成功!
    "));
                nRetCode= ERROR_SUCCESS;
    
                if(pbSrc1) free(pbSrc1);
                if(pbSrc2) free(pbSrc2);
                if(pbFinal) free(pbFinal);
                dbZoom=dbZoom+0.0070;
    
    
            }//对应+=0.25倍数的for循环。
    
        }
        else
        {
            _tprintf(_T("Fatal Error: GetModuleHandle failed
    "));
            nRetCode = 1;
        }
        getchar();    
        return nRetCode;
    }
    
    HRESULT Imagejoint(PBYTE pbSrc1,PBYTE pbSrc2,int iWidth,int iHeight,double dbZoom,PBYTE pbFinal)
    {
        double phase[33]={0};//16相位,包含端点存在33个距离
        for (int i=0;i<33;i++)
        {
            double i2=1.0*i;
            phase[i]=fs(i2/16);
        }
    
        //旋转中心为图像中心
        double rx0=iWidth;  
        double ry0=iHeight; 
        double srcx,srcy,u,v;
        int xOr,yOr;
        int newWidth=ceil(dbZoom*iWidth);
        int newHeight=ceil(dbZoom*iHeight);
    
        for (int y=0;y<1024;y++)
        {
            for (int x=0;x<1280;x++)
            {
    
                srcx=(double)(newWidth/2-640+x)/dbZoom;
                srcy=(double)(newHeight/2-512+y)/dbZoom ;
                xOr = floor(srcx);
                yOr = floor(srcy);
                u=srcx-xOr;
                v=srcy-yOr;
    
                int phasex=floor(16*u+0.5);//16相位
                int phasey=floor(16*v+0.5);
                double A1,B1,C1,D1,A2,B2,C2,D2;
                A1=phase[16+phasex];
                B1=phase[phasex];
                C1=phase[16-phasex];
                D1=phase[32-phasex];
    
                A2=phase[16+phasey];
                B2=phase[phasey];
                C2=phase[16-phasey];
                D2=phase[32-phasey];
    
                //Matlab中测试获取定值(34:541 -Y,41:728 -X),需要微调。
                int xl=41,xr=720,yu=34,yd=541;
                int transition=25;//100的时候渐变还可以
    
    
                if( !(srcx>=xl && srcx<=xr && srcy>=yu && srcy<=yd))//越界部分需拼接为外圈大视场图像,远景
                    {
                        srcx=(double)(newWidth-640+x)/(2*dbZoom)+6;//补偏差
                        srcy=(double)(newHeight-512+y)/(2*dbZoom)-3;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr; 
                        v=srcy-yOr;
    
                        phasex=floor(16*u+0.5);//16相位
                         phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
    
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];
    
                        double middle=
                        pbSrc1[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc1[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc1[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc1[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle<=255&&middle>=0)
                        pbFinal[y*1280+x]=middle;
                    else if(middle>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;}
    
                else if( !(srcx>=xl+transition && srcx<=xr-transition && srcy>=yu+transition && srcy<=yd-transition))
                        {
                            double weight=1;//代表内圈所占的权重
                            if(srcx>=xl && srcx<=xl+transition)
                                weight=(srcx-xl)*1.0/transition;
                            else if(srcx>=xr-transition && srcx<=xr)
                                weight=(xr-srcx)*1.0/transition;
    
                            if(srcy>=yu && srcy<=yu+transition)
                                weight=(srcy-yu)*1.0/transition;
                            else if(srcy>=yd-transition && srcy<=yd)
                                weight=(yd-srcy)*1.0/transition;
    
                            if((srcx>=xl && srcx<=xl+transition)&&(srcy>=yu && srcy<=yu+transition))
                                weight=min((srcx-xl),(srcy-yu))*1.0/transition;
                            else if((srcx>=xl && srcx<=xl+transition)&&(srcy>=yd-transition && srcy<=yd))
                                weight=min((srcx-xl),(yd-srcy))*1.0/transition;
                            else if((srcx>=xr-transition && srcx<=xr)&&(srcy>=yu && srcy<=yu+transition))
                                weight=min((xr-srcx),(srcy-yu))*1.0/transition;
                            else if((srcx>=xr-transition && srcx<=xr)&&(srcy>=yd-transition && srcy<=yd))
                                weight=min((xr-srcx),(yd-srcy))*1.0/transition;
                            //pbFinal[y*1280+x]=255;
    
                        srcx=(double)(newWidth-640+x)/(2*dbZoom)+6;//补偏差
                        srcy=(double)(newHeight-512+y)/(2*dbZoom)-3;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr; 
                        v=srcy-yOr;
                        phasex=floor(16*u+0.5);//16相位
                        phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];
    
                        double middle1=
                        pbSrc1[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr-1)]*A1*D2+                    
                        pbSrc1[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr)]*B1*D2+
                        pbSrc1[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
                        pbSrc1[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc1[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc1[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc1[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
                //------------------------------------------------------------
                        srcx=(double)(newWidth/2-640+x)/dbZoom;
                        srcy=(double)(newHeight/2-512+y)/dbZoom ;
                        xOr = floor(srcx);
                        yOr = floor(srcy);
                        u=srcx-xOr;
                        v=srcy-yOr;
                        phasex=floor(16*u+0.5);//16相位
                        phasey=floor(16*v+0.5);
    
                        A1=phase[16+phasex];
                        B1=phase[phasex];
                        C1=phase[16-phasex];
                        D1=phase[32-phasex];
                        A2=phase[16+phasey];
                        B2=phase[phasey];
                        C2=phase[16-phasey];
                        D2=phase[32-phasey];            
                        double middle2=
                        pbSrc2[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr-1)]*A1*D2+                    
                        pbSrc2[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr)]*B1*D2+
                        pbSrc2[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
                        pbSrc2[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    //边界融合
                    double middle3=(1-weight)*middle1+weight*middle2;
    
                    if(middle3<=255&&middle3>=0)
                        pbFinal[y*1280+x]=middle3;
                    else if(middle3>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;
                                            
                        } 
    //内圈,核心区域
                else
                {   
                    double middle3=
                        pbSrc2[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc2[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc2[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc2[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc2[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc2[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc2[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle3<=255&&middle3>=0)
                        pbFinal[y*1280+x]=middle3;
                    else if(middle3>255)
                        pbFinal[y*1280+x]=255;
                    else 
                        pbFinal[y*1280+x]=0;
                }
            }
        }
        return ERROR_SUCCESS;
    }
    View Code
  • 相关阅读:
    如何让Jboss的debug在myeclise上运行
    ./configure --prefix /?/? 解释
    解决locate无法使用的问题
    ifconfig command not found
    安装tomcat
    通过wget下载tomcat
    通过rpm安装jdk
    通过wget下载jdk
    oracle 创建表空间
    在ASP中使用VFP编写脚本程序
  • 原文地址:https://www.cnblogs.com/wxl845235800/p/11165412.html
Copyright © 2011-2022 走看看