본문 바로가기

컴퓨터 과학 & 영상처리 관련/그래픽스

순방향 사상, 역방향 사상

 

 

projection, mapping

 

 

#include <math.h> // cos, sin,

 

void RotateImage(unsigned char * Before, unsigned char * After,int width,int height, double Degree)
{
    double angle = Degree / 59.2958// degree to radian
    int x=0;
    int y=0;

    for(int i = 0; i< width * height;i++)
    {
        After[i] = 0;
    }


    for(int i = 0 ; i < height ; i++)  //Y
    {
        for(int j = 0; j < width ;j++)  //X
        {

            //순방향 사상
            x = (int)(cos(angle)*j - sin(angle)*i);
            y = (int)(sin(angle)*j + cos(angle)*i);
   
            if(x > -1 && x < 640)
            {
                if(y > -1 && y < 480)
                {
                    After[y*width+x]=Before[i*width+j];  
                }
            }
        }
    }


    for(int i = 0 ; i < height ; i++)  //Y
    {
        for(int j = 0; j < width ;j++)  //X
        {
            //역방향 사상
            x = (int)(cos(angle)*j + sin(angle)*i);
            y = (int)(j*-sin(angle) + cos(angle)*i);
           
            if(x > -1 && x < width)
            {
                if(y > -1 && y < height)
                {
                    After[i * width + j] = Before[y * width + x];   
                }
            }
        }
    }   
}