Ask Your Question
0

problem with Affine warping

asked 2017-06-06 08:59:19 -0600

Kumar123 gravatar image

updated 2017-06-06 09:02:54 -0600

I am very beginner to coding as well as image processing. I just need to warp an image by using affine transformation and need to see the image how it would be appeared without interpolation. Actually My goal is to implement an interpolation method (Bicubic or linear interpolation). I have only theoretical knowledge on interpolation, but coming to coding i do not know how find out the newly created images in warped image and give the calculated value in it. meanwhile i just need to see how the following function would work, but the code is unable to be run.

         Mat imgAffine, image, par;
        image = imread ("/media/sf_vbox_share/ubuntushare/board.jpg",1);

        par.at<double>(0,0)=  1.01121;  //p1
        par.at<double>(1,0)=  0.21067 ;  //p2;
        par.at<double>(0,1)= -89.69693; //p3;
        par.at<double>(1,1)= - 0.11557;  //p4;
        par.at<double>(0,2)= 1.44982;   //p5;
        par.at<double>(1,2)= -193.66149;//p6;

          imgAffine = Mat::zeros( image.rows, image.cols,image.type());
           warpAffine(image,imgAffine,par, image.size(),INTER_LINEAR);
           namedWindow("image",WINDOW_AUTOSIZE);
                       imshow("image",imgAffine);

            cvWaitKey(0);

Could anyone tell me what mistake I am doing here...

edit retag flag offensive close merge delete

Comments

and the problem is ? (apart from the probable crash ...)

berak gravatar imageberak ( 2017-06-06 09:04:17 -0600 )edit

it is showing that code is crashed..... only that..

Kumar123 gravatar imageKumar123 ( 2017-06-06 09:07:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-06 10:09:25 -0600

berak gravatar image

updated 2017-06-06 10:33:59 -0600

before you can assign values to your transformation Mat, you have to allocate space for those values:

    Mat par(2,3,CV_64F);

    par.at<double>(0,0)=  1.01121;  //p1
    par.at<double>(1,0)=  0.21067 ;  //p2;
    par.at<double>(0,1)= -89.69693; //p3;
    par.at<double>(1,1)= - 0.11557;  //p4;
    par.at<double>(0,2)= 1.44982;   //p5;
    par.at<double>(1,2)= -193.66149;//p6;

please also have a look at getAffineTransform (from 3 2d points)

edit flag offensive delete link more

Comments

@berak thank you so much for the help. It is working fine now.

After Affine transformation, we will get distortion in the image due to newly created pixels. So i need to implement he Bilinear interpolation function to increase the quality. I have theoretical knowledge, but coming to coding, i unable to start implementation. I can write the code for the algorithm, but How can I find the newly created pixels by using any Opencv function. Could please suggest me any article regarding coding.....

Kumar123 gravatar imageKumar123 ( 2017-06-09 04:40:48 -0600 )edit

shouldn't you rather use a bilinear flag in the warpAffine function ?

berak gravatar imageberak ( 2017-06-09 05:23:21 -0600 )edit

@berak Not really.. My project goal is to implement own function for bilinear interpolation. And as i have observed that bilinear flag is not so accurate. I have seen both resulting images with and without that flag both have almost similar distortion. I need to know how to get the location of newly created Non integer coordinate pixels and how to access their weights.

Kumar123 gravatar imageKumar123 ( 2017-06-09 06:55:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-06 08:59:19 -0600

Seen: 206 times

Last updated: Jun 06 '17