Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

remap irregular to regular grid

hi there,

I'm use the remap function to map a irregular grid( 650 xyz-coordinates ) to a regular one ( 160x160 points from -5....5 step 1/160) but I can't seem to get it working. By the way the interpolation that I use is bicubic. Can someone please tell me if it's even possible to do it like this? thanks in advance.

    using namespace cv;
using namespace POINTS;

Mat src,dst;
Mat map_x, map_y;
int ind = 0;

// pointsx, pointsy, pointsz are coming from the POINTS namespace
Mat matx( 400, 1, CV_64F, &pointsx );
Mat maty( 400, 1, CV_64F, &pointsy );
Mat matz( 400, 1, CV_64F, &pointsz );

void createMatrixX( Mat& mat );
void createMatrixY( Mat& mat );

int main()
{
 hconcat( matx, maty, matx );
 hconcat( matx, matz, src );

 //src has 650 rows( points )  and 3 cols (xyz doubles ) 
 dst.create( 160,160, src.type());
 map_x.create( 160,160, CV_32FC1 );
 map_y.create( 160,160, CV_32FC1 );

 createMatrixX( map_x );
 createMatrixY( map_y );

 //it crashes here 
 remap( src, dst, map_x, map_y, CV_INTER_CUBIC, BORDER_CONSTANT, Scalar(0, 0, 0) );

 return 0;
}

void createMatrixX( Mat& mat )
{ 

   for( int i=0; i<mat.rows; i++)
      for( int j=0; j<mat.cols; j++ )
      {
         double value = -1. + (j*2./(mat.rows-1));
         mat.at<double>(i,j) = 5. * value;
      }

}

void createMatrixY( Mat& mat ) {

   for( int i=0; i<mat.rows; i++)
       for( int j=0; j<mat.cols; j++ )
       {
           double value = -1. + (j*2./(mat.rows-1));
           mat.at<double>(j,i) = 5. * value;
       }

}

remap irregular to regular grid

hi there,

I'm use the remap function to map a irregular grid( 650 xyz-coordinates ) to a regular one ( 160x160 points from -5....5 step 1/160) but I can't seem to get it working. By the way the interpolation that I use is bicubic. Can someone please tell me if it's even possible to do it like this? thanks in advance.

 using namespace cv;
using namespace POINTS;

Mat src,dst;
Mat map_x, map_y;
int ind = 0;

// pointsx, pointsy, pointsz are coming from the POINTS namespace
Mat matx( 400, 1, CV_64F, &pointsx );
Mat maty( 400, 1, CV_64F, &pointsy );
Mat matz( 400, 1, CV_64F, &pointsz );

void createMatrixX( Mat& mat );
void createMatrixY( Mat& mat );

int main()
{
 hconcat( matx, maty, matx );
 hconcat( matx, matz, src );

 //src has 650 rows( points )  and 3 cols (xyz doubles ) 
 dst.create( 160,160, src.type());
 map_x.create( 160,160, CV_32FC1 );
 map_y.create( 160,160, CV_32FC1 );

 createMatrixX( map_x );
 createMatrixY( map_y );

 //it crashes here 
 remap( src, dst, map_x, map_y, CV_INTER_CUBIC, BORDER_CONSTANT, Scalar(0, 0, 0) );

 return 0;
}

void createMatrixX( Mat& mat )
{ 
 
   for( int i=0; i<mat.rows; i++)
      for( int j=0; j<mat.cols; j++ )
      {
         double value = -1. + (j*2./(mat.rows-1));
         mat.at<double>(i,j) = 5. * value;
      }

}

} } void createMatrixY( Mat& mat ) {

{
    for( int i=0; i<mat.rows; i++)
      for( int j=0; j<mat.cols; j++ )
      {
          double value = -1. + (j*2./(mat.rows-1));
          mat.at<double>(j,i) = 5. * value;
      }
}

}

remap irregular to regular grid

hi there,

I'm use the remap function to map a irregular grid( 650 xyz-coordinates ) to a regular one ( 160x160 points from -5....5 step 1/160) but I can't seem to get it working. By the way the interpolation that I use is bicubic. Can someone please tell me if it's even possible to do it like this? thanks in advance.

using namespace cv;
using namespace POINTS;

Mat src,dst;
Mat map_x, map_y;
int ind = 0;

// pointsx, pointsy, pointsz are coming from the POINTS namespace
Mat matx( 400, 650, 1, CV_64F, &pointsx );
Mat maty( 400, 650, 1, CV_64F, &pointsy );
Mat matz( 400, 650, 1, CV_64F, &pointsz );

void createMatrixX( Mat& mat );
void createMatrixY( Mat& mat );

int main()
{
 hconcat( matx, maty, matx );
 hconcat( matx, matz, src );

 //src has 650 rows( points )  and 3 cols (xyz doubles ) 
 dst.create( 160,160, src.type());
 map_x.create( 160,160, CV_32FC1 );
 map_y.create( 160,160, CV_32FC1 );

 createMatrixX( map_x );
 createMatrixY( map_y );

 //it crashes here 
 remap( src, dst, map_x, map_y, CV_INTER_CUBIC, BORDER_CONSTANT, Scalar(0, 0, 0) );

 return 0;
}

void createMatrixX( Mat& mat )
{ 
   for( int i=0; i<mat.rows; i++)
     for( int j=0; j<mat.cols; j++ )
     {
         double value = -1. + (j*2./(mat.rows-1));
         mat.at<double>(i,j) = 5. * value;
     }
}

void createMatrixY( Mat& mat )
{
    for( int i=0; i<mat.rows; i++)
     for( int j=0; j<mat.cols; j++ )
     {
         double value = -1. + (j*2./(mat.rows-1));
         mat.at<double>(j,i) = 5. * value;
     }
}

remap irregular to regular grid

hi there,

I'm use the remap function to map a irregular grid( 650 xyz-coordinates ) to a regular one ( 160x160 points from -5....5 step 1/160) but I can't seem to get it working. By the way the interpolation that I use is bicubic. Can someone please tell me if it's even possible to do it like this? thanks in advance.

using namespace cv;
using namespace POINTS;

Mat src,dst;
Mat map_x, std::ofstream file;
Mat src(400,3,CV_32F);
Mat dst(160,160,CV_32F);
Mat map_x;
Mat map_y;
int ind = 0;

// pointsx, pointsy, pointsz are coming from the POINTS namespace
Mat matx( 650, 400, 1, CV_64F, CV_32F, &pointsx );
Mat maty( 650, 400, 1, CV_64F, CV_32F, &pointsy );
Mat matz( 650, 400, 1, CV_64F, CV_32F, &pointsz );

 void createMatrixX( Mat& matrixDump( const Mat* mat );
void createMatrixY( Mat& createMatrix( Mat* mat );

int main()
{
  hconcat( matx, maty, matx );
  hconcat( matx, matz, src );

 //src has 650 rows( points )  and 3 cols (xyz doubles ) 
  dst.create( 160,160, src.type());
  map_x.create( 160,160, CV_32FC1 );
  map_y.create( 160,160, 160, 160, CV_32FC1 );

 createMatrixX( map_x );
 createMatrixY( map_y );

 //it crashes here 
  createMatrix( &map_x );
   createMatrix( &map_y );
   Mat T = map_y.t();

   remap( src, dst, map_x, map_y, T, CV_INTER_CUBIC, BORDER_CONSTANT, Scalar(0, 0, 0) );

  return 0;
}

 void createMatrixX( Mat& matrixDump( const Mat* mat )
{
    file.open("interpolation.txt");

    for( int i=0; i<mat->rows ; i++ )
    {
       for( int j=0; j<mat->cols;j++)
       {
           file << mat->at<float>(i,j) << " " ;
       }
       file << std::endl;
    }
    file.close();
}


void createMatrix( Mat* mat )
{  
   for( int i=0; i<mat.rows; i<mat->rows; i++)
   {
       for( int j=0; j<mat.cols; j<mat->cols; j++ )
     {
         double   {
           float value = -1. + (j*2./(mat.rows-1));
         mat.at<double>(i,j) (j*2./(mat->rows-1));
           mat->at<float>(i,j) = 5. * value;
     }
}

void createMatrixY( Mat& mat )
{
    for( int i=0; i<mat.rows; i++)
     for( int j=0; j<mat.cols; j++ )
     {
         double value = -1. + (j*2./(mat.rows-1));
         mat.at<double>(j,i) = 5. * value;
    }
   }
}

remap irregular to regular grid

hi there,

I'm use using the remap function to map a irregular grid( 650 xyz-coordinates ) to a regular one ( 160x160 points from -5....5 step 1/160) but I can't seem to get it working. By the way the interpolation that I use is bicubic. Can someone please tell me if it's even possible to do it like this? thanks in advance.

using namespace cv;
using namespace POINTS;

std::ofstream file;
Mat src(400,3,CV_32F);
Mat dst(160,160,CV_32F);
Mat map_x;
Mat map_y;
int ind = 0;

Mat matx( 400, 1, CV_32F, &pointsx );
Mat maty( 400, 1, CV_32F, &pointsy );
Mat matz( 400, 1, CV_32F, &pointsz );


void matrixDump( const Mat* mat );
void createMatrix( Mat* mat );

int main()
{
   hconcat( matx, maty, matx );
   hconcat( matx, matz, src );

   dst.create( 160,160, src.type());
   map_x.create( 160,160, CV_32FC1 );
   map_y.create( 160, 160, CV_32FC1 );

   createMatrix( &map_x );
   createMatrix( &map_y );
   Mat T = map_y.t();

   remap( src, dst, map_x, T, CV_INTER_CUBIC, BORDER_CONSTANT, Scalar(0, 0, 0) );

   return 0;
}


void matrixDump( const Mat* mat )
{
    file.open("interpolation.txt");

    for( int i=0; i<mat->rows ; i++ )
    {
       for( int j=0; j<mat->cols;j++)
       {
           file << mat->at<float>(i,j) << " " ;
       }
       file << std::endl;
    }
    file.close();
}


void createMatrix( Mat* mat )
{     
   for( int i=0; i<mat->rows; i++)
   {
       for( int j=0; j<mat->cols; j++ )
       {
           float value = -1. + (j*2./(mat->rows-1));
           mat->at<float>(i,j) = 5. * value;
       }
   }
}