Error with interpolation function c++ [closed]

asked 2017-06-13 09:52:05 -0600

Priya KUMARI gravatar image

My project goal is to implement own function for Bilinear interpolation after Affine transformation. As I am beginner I could not find solution to locate the non integer coordinates after the image transformation, So I did like following. It is showing error after the execution as "cannot convert 'x' (type 'double*') to type 'cv::Point' ".

int main()
    {
        double value =0.0 ;double i,j;
        const cv::Mat img = cv::imread("/media/sf_vbox_share/ubuntushare/chess2.jpg",CV_8U);    
               Mat imgAffine;
                Mat par(2, 3, CV_64FC1);   

            imgAffine = Mat::zeros( img.rows, img.cols,CV_32FC1);    
                        par.at<double>(0,0)=   1;  //p1
                        par.at<double>(1,0)=  0.02  ;  //p2;
                        par.at<double>(0,1)= -0.03 ; //p3;
                        par.at<double>(1,1)= 1 ;  //p4;
                        par.at<double>(0,2)= -0.001 ;   //p5;
                        par.at<double>(1,2)= -0.005;//p6;
                         warpAffine(img,imgAffine,par, img.size());

           namedWindow("image",WINDOW_AUTOSIZE);
            imshow("image",imgAffine); 
          //for locating non integer coordinates..     
                        for(i=0.0;i< imgAffine.rows ; i += 0.1)
                       {
                          for(j=0.0;j< imgAffine.cols; j+= 0.1) {

                                       Bil_interp(imgAffine,&i,&j,&value);
                           }}

    imshow("interpol img",imgAffine);    
                        waitKey(0);
         return 0;
    }

    void Bil_interp(const Mat& image, double* x, double* y, double* val)
    {    
        int x1 = cvFloor(x);int y1 = cvFloor(y);
        int x2 = x1+1;int y2 = y1+1;
        double q11,q12,q21, q22;    
        q11 = (image.at<double>(x1,y1));
        q21 = (image.at<double>(x2,y1));
        q12 = (image.at<double>(x1,y2));
        q22 = (image.at<double>(x2,y2));

        val = ((1/( (x2-x1)*(y2-y1) ) ) *(q11*(x2-x)*(y2-y)+q21*(x2-x1)*(y2-
       y) +q12*(x2-x)*(y-y1)+q22*(x-x1)*(y-y1)));

     image.at<double>(x,y) = val;

      }

I really do not know how to use CV::Point in the code. And I am not allowed to use interpolation flag in warpaffine function. Can anyone suggest me how to solve the problem here. How exactly we could know there are non integer coordinates after the transformation.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-18 05:00:01.526265

Comments

there's a couple of misconceptions in your code.first, warpAffine() will reallocate the output to CV_8U, so your imgAffine is NOT CV_32F as expected. IF your Mat would be CV_32F, you'd have to access it as img.at<float>(y,x) , double is the wrong type. then, at() takes integer coords, not double, and you cannot do anything on subpixel level using that. also, if you do like: x2 = x1+1 , you need to spare a 1 pixel border from the iteration, else you go out-of-bounds.

all in all, you should avoid using Mat::at()

berak gravatar imageberak ( 2017-06-14 00:03:23 -0600 )edit

do you understand, that there is no subpixel coord access in opencv ?

berak gravatar imageberak ( 2017-06-14 03:01:22 -0600 )edit

@berak. As I have understood from [Geometric transformation] (http://docs.opencv.org/2.4/modules/im...). After the image transformation or warping. There will be newly created pixels (non integer coordinates or floating coordinates). I thought those will be created between main pixels. How can we retrieve those values. Could you please explain me more specifically. my project goal is to implement Bilinear interpolation function.

Priya KUMARI gravatar imagePriya KUMARI ( 2017-06-14 03:14:40 -0600 )edit