• 相位插值


    1、原旋转中的

        double phase[33]={0};//16相位,包含端点存在33个距离
        for (int i=0;i<33;i++)
        {
            double i2=1.0*i;
            phase[i]=fs(i2/16);
        }
        int size;
        if(dbZoom>1)
        {
            size=iWidth*iHeight;
        }
        else
        {
            size=ceil(iWidth*dbZoom)*ceil(iHeight*dbZoom);
        }
        int newWidth=ceil(dbZoom*iWidth);
        //旋转中心为图像中心
        double rx0=ceil(dbZoom*iWidth)*0.5;  
        double ry0=ceil(dbZoom*iHeight)*0.5; 
        double srcx,srcy,u,v;
        int xOr,yOr;
        dbRotate=dbRotate*3.1415926/180.0;
        for (int y=0;y<ceil(dbZoom*iHeight);y++)
        {
            for (int x=0;x<ceil(dbZoom*iWidth);x++)
            {
                srcx=(double)((x-rx0)*cos(dbRotate) - (y-ry0)*sin(dbRotate) + rx0) ;
                srcy=(double)((x-rx0)*sin(dbRotate) + (y-ry0)*cos(dbRotate) + ry0) ;
                srcx=srcx*1/dbZoom;
                srcy=srcy*1/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];
    
            /*    A1=fs(1+u);
                B1=fs(u);
                C1=fs(1-u);
                D1=fs(2-u);
    
                A2=fs(1+v);
                B2=fs(v);
                C2=fs(1-v);
                D2=fs(2-v);*/
    
                int newWidth=ceil(dbZoom*iWidth);
                if( !(xOr-1>=0 && xOr+2<=iWidth && yOr-1>=0 && yOr+2<=iHeight))
                    {
                        pbTag[y*newWidth+x]=0;
                    }
                else
                {   
                    double middle=
                        pbSrc[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle<=255&&middle>=0)
                        pbTag[y*newWidth+x]=middle;
                    else if(middle>255)
                        pbTag[y*newWidth+x]=255;
                    else 
                        pbTag[y*newWidth+x]=0;
                }
            }
        }
        //memcpy(pbTag,pbSrc,size);
        return ERROR_SUCCESS;
    View Code

    2、插值后只显示中间1280*1024。

        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<ceil(dbZoom*iHeight);y++)
        {
            for (int x=0;x<ceil(dbZoom*iWidth);x++)
            {
    
                srcx=(double)x;
                srcy=(double)y ;
                srcx=srcx*1/dbZoom;
                srcy=srcy*1/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];
    
    
                if( !(srcx>=0 && srcx<=iWidth && srcy>=0 && srcy<=iHeight))
                    {
                        pbTag[y*2*iWidth+x]=0;//255
                    }
                else
                {   
                    double middle=
                        pbSrc[(yOr-1)*iWidth+(xOr-1)]*A1*A2+
                        pbSrc[(yOr)*iWidth+(xOr-1)]*A1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr-1)]*A1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr-1)]*A1*D2+
                        
                        pbSrc[(yOr-1)*iWidth+(xOr)]*B1*A2+
                        pbSrc[(yOr)*iWidth+(xOr)]*B1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr)]*B1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr)]*B1*D2+
    
                        pbSrc[(yOr-1)*iWidth+(xOr+1)]*C1*A2+
                        pbSrc[(yOr)*iWidth+(xOr+1)]*C1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr+1)]*C1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr+1)]*C1*D2+
    
                        pbSrc[(yOr-1)*iWidth+(xOr+2)]*D1*A2+
                        pbSrc[(yOr)*iWidth+(xOr+2)]*D1*B2+
                        pbSrc[(yOr+1)*iWidth+(xOr+2)]*D1*C2+
                        pbSrc[(yOr+2)*iWidth+(xOr+2)]*D1*D2;
    
                    if(middle<=255&&middle>=0)
                        pbTag[y*newWidth+x]=middle;
                    else if(middle>255)
                        pbTag[y*newWidth+x]=255;
                    else 
                        pbTag[y*newWidth+x]=0;
                }
            }
        }
    
        for (int y=0;y<1024;y++)
        {
            for (int x=0;x<1280;x++)
            {
                int y2=newHeight/2-512;
                int x2=newWidth/2-640;
                 pbFinal[y*1280+x]=pbTag[(y2+y)*newWidth+(x2+x)];
           }
        }
        return ERROR_SUCCESS;
    View Code

    双三。

  • 相关阅读:
    【HDU4261】Estimation-DP+优先队列优化
    【POJ3744】Scout YYF I-概率DP+矩阵加速优化
    【POJ3744】Scout YYF I-概率DP+矩阵加速优化
    【HDU2294】Pendant-DP矩阵优化
    【HDU2294】Pendant-DP矩阵优化
    【BZOJ1269】文本编辑器editor(AHOI2006)-NOI原题升级版
    【BZOJ1269】文本编辑器editor(AHOI2006)-NOI原题升级版
    【NOI2003T2】文本编辑器Editor-伸展树数列操作
    zk create() 方法
    FLUSH TABLES WITH READ LOCK 锁全局
  • 原文地址:https://www.cnblogs.com/wxl845235800/p/11152049.html
Copyright © 2020-2023  润新知