# problem with Affine warping

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;

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 close merge delete

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

( 2017-06-06 09:04:17 -0500 )edit

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

( 2017-06-06 09:07:32 -0500 )edit

Sort by ยป oldest newest most voted

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)

more

@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.....

( 2017-06-09 04:40:48 -0500 )edit

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

( 2017-06-09 05:23:21 -0500 )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.

( 2017-06-09 06:55:27 -0500 )edit

Official site

GitHub

Wiki

Documentation