Exemplo n.º 1
0
void ScvRipper::selectImage(const QItemSelection& selected,  const QItemSelection& deselected)
{
	if(selected.indexes().isEmpty()) return;

	QModelIndex index = selected.indexes().first();
	QString name = index.data(Qt::DisplayRole).toString();

	int row = index.row();

	QString imagePath = this->imageFolder + "/" + name;
	QImage orignalImage;
	orignalImage.load(imagePath);

	QImage dispImg = orignalImage.scaled(originalImgLabel->width(), originalImgLabel->height(), Qt::AspectRatioMode::KeepAspectRatio);
	originalImgLabel->setPixmap(QPixmap::fromImage(dispImg));

	QString edgePath = this->outputFolder + QString::number(row+1) + "_c_edge.png";
	QImage edgeImage(edgePath);
	if(!edgeImage.isNull() && finish_map[name.toStdString()].f1)
	{
		dispImg = edgeImage.scaled(edgeLabel->width(), edgeLabel->height(), Qt::AspectRatioMode::KeepAspectRatio);
		edgeLabel->setPixmap(QPixmap::fromImage(dispImg));
	}
	else
	{
		edgeLabel->clear();
	}

	QString vcPath = this->outputFolder + QString::number(row+1) + "_visualcues.png";
	QImage vcImage(vcPath);
	if(!vcImage.isNull() && finish_map[name.toStdString()].f2)
	{
		dispImg = vcImage.scaled(vcLabel->width(), vcLabel->height(), Qt::AspectRatioMode::KeepAspectRatio);
		vcLabel->setPixmap(QPixmap::fromImage(dispImg));
	}
	else
	{
		vcLabel->clear();
	}

	QString exPath = this->outputFolder + QString::number(row+1) + "_frame.png";
	QImage exImage(exPath);
	if(!exImage.isNull() && finish_map[name.toStdString()].f3)
	{
		dispImg = exImage.scaled(extractedLabel->width(), extractedLabel->height(), Qt::AspectRatioMode::KeepAspectRatio);
		extractedLabel->setPixmap(QPixmap::fromImage(dispImg));
	}
	else
	{
		extractedLabel->clear();
	}
}
Exemplo n.º 2
0
/*
 * Edge function compares binarized image with gradien image, throw AND Operator
 * The algorithm checks for white pixels in both images and if true then apply white to final image
 *
 * @param binarized		Contains binarized image
 * @param gradient		Contains gradient image
 *
 * @return edgeImage 	Contains the result image
 */
Mat edge(const Mat& binarized, const Mat& gradient){
	Size s = binarized.size();
	int xmax = s.height;
	int ymax = s.width;

	Mat edgeImage(xmax,ymax, CV_8UC1, Scalar(0));


	for (int i=0; i < xmax; i++){
		for (int j=0; j < ymax; j++){
			//If both pixels are equals and white, then we apply white to the final image (AND Operator)
			if(binarized.at<uchar>(i,j) == gradient.at<uchar>(i,j) && binarized.at<uchar>(i,j) == MAX_BRIGHTNESS_8)
				edgeImage.at<uchar>(i,j) = MAX_BRIGHTNESS_8;
			else
				edgeImage.at<uchar>(i,j) = 0;
		}
	}

	double min;
		double max;
		minMaxIdx(edgeImage, &min, &max);
		cout << "Max: " << max << "Minnn: " << min << endl;
		waitKey(0);
/*
	imwrite( "edge.tiff", edgeImage );
	imwrite( "binary.tiff", binarized );
	imwrite( "gradient.tiff", gradient );

	Mat image;
	binarized.convertTo(image, CV_32SC1);
	imwrite( "image.tiff", image );
*/

	imshow("edgeimage", edgeImage);
	waitKey(0);
	imshow("binarizada", binarized);
	waitKey(0);
	imshow("gradiente", gradient);
	waitKey(0);

	return gradient;
}
Exemplo n.º 3
0
int main( int argc, char* argv[] )
{
	int argc2 = 2;
	char* argv2[2] = { "", "-device=1" };

	cudaDeviceProp deviceProp;
    int devID = cutilChooseCudaDevice( argc2, argv2 );
    if( devID < 0 )
	{
       printf( "exiting...\n" );
       cutilExit( argc, argv );
       exit( 0 );
    }
    cutilSafeCall( cudaGetDeviceProperties( &deviceProp, devID ) );

	//Image4f im( "c:/tmp/tulip.png" );
	//Image4f im( "c:/tmp/tulip_1080.png" ); // Jiawen version
	Image4f im( "../../apps/bilateral_grid/input.png" );
	//Image4f im( "c:/tmp/church_panorama_5097x2889.pfm" );

	im = im.flipUD();

	Array2D< float > data( im.width(), im.height() );
	Array2D< float > output( im.width(), im.height() );

	for( int y = 0; y < im.height(); ++y )
	{
		for( int x = 0; x < im.width(); ++x )
		{
			Vector3f rgb = im.pixel( x, y ).xyz();
            // float lum = ColorUtils::rgb2luminance( rgb );
            // data( x, y ) = lum;
            // jrk: just use red
            data( x, y ) = rgb[0];
		}
	}

	testBilateralFilter( data, 8, 0.1f, output );
	saveArrayAsImage( output, "bf", 8, 0.1f );
	testBilateralFilter( data, 16, 0.1f, output );
	saveArrayAsImage( output, "bf", 16, 0.1f );
	testBilateralFilter( data, 32, 0.2f, output );
	saveArrayAsImage( output, "bf", 32, 0.2f );
	testBilateralFilter( data, 64, 0.4f, output );
	saveArrayAsImage( output, "bf", 64, 0.4f );
    
#if 0
	Image4f edgeImage( "/tmp/step.png" );
	edgeImage.flipUD();

	Array2D< float > edge( im.width(), im.height() );
	for( int y = 0; y < im.height(); ++y )
	{
		for( int x = 0; x < im.width(); ++x )
		{
			edge( x, y ) = edgeImage.pixel( x, y ).x;
		}
	}

	testCrossBilateralFilter( data, edge, 16, 0.1f, output );
	saveArrayAsImage( output, "cbf", 16, 0.1f );
	testCrossBilateralFilter( data, edge, 32, 0.2f, output );
	saveArrayAsImage( output, "cbf", 32, 0.2f );
	testCrossBilateralFilter( data, edge, 64, 0.4f, output );
	saveArrayAsImage( output, "cbf", 64, 0.4f );
#endif

	return 0;
}
bool
CppDetEstCircle4 (vector < double >x, vector < double >y,
                  double cellsize, unsigned int maxR, unsigned int sigmacoef,
                  double epsion, unsigned int maxIter, unsigned int minnumfit,
                  vector < double >&detectedcircle,
                  vector < double >&mapfinalHTcircle,
                  vector < double >&iterationdata, vector < double >&ArcInfo,
                  vector < double >&finalx, vector < double >&finaly,
                  vector < double >&DebugInfo)
{
  // based from 0.
  // detectedcircle: [yc, xc, r], in unit of meter.
  // mapfinalHTcircle: [rowc, colc, r], in unit of pixel.
  if (x.size () != y.size ()) {
#ifdef MATLABPRINT
    mexPrintf
      ("CppDetEstCircle ==> input x and y do not have the same length!\n");
#endif
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    ArcInfo.clear ();
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return false;
  }
  mxArray *mx_x, *mx_y, *mx_refmatrix;
  double *tempGetPr;

  vector < unsigned int >img, dim_img (2), dim_refmatrix (2);
  vector < double >refmatrix;
  // call CppGridPts to grid the points cloud into cellsize*cellsize cells
  bool callflag;
  callflag =
    CppGridPts (x, y, cellsize, maxR, minnumfit, img, dim_img, refmatrix,
                dim_refmatrix);
  if (!callflag) {
#ifdef MATLABPRINT
    mexPrintf ("CppDetEstCircle ==> calling CppGridPts failed!\n");
#endif
    // maybe inputs are invalid!
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    ArcInfo.clear ();
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return false;
  }
  if (img.size () == 0 || refmatrix.size () == 0) {
    // less than minnumfit points in this section
#ifdef DEBUG
    mexPrintf
      ("CppDetEstCircle ==> calling CppGridPts ==> less than minnumfit points in this section!\n");
#endif
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    iterationdata.resize (4, 0.0);
    iterationdata[0] = 0.0;
    iterationdata[1] = mxGetNaN ();
    iterationdata[2] = mxGetNaN ();
    iterationdata[3] = static_cast < double >(x.size ());
    ArcInfo.clear ();
    ArcInfo.resize (3, 0.0);
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return true;
  }
  // convert x, y to row and col by MATLAB function: map2pix
  // xpix, ypix: based from 0.
  vector < double >xpix (x.size ()), ypix (y.size ());
  mxArray *prhs[3], *plhs[2];
  mx_x = mxCreateDoubleMatrix (x.size (), 1, mxREAL);
  mx_y = mxCreateDoubleMatrix (y.size (), 1, mxREAL);
  mx_refmatrix =
    mxCreateDoubleMatrix (dim_refmatrix[0], dim_refmatrix[1], mxREAL);
  tempGetPr = mxGetPr (mx_x);
  for (unsigned int i = 0; i < x.size (); i++) {
    tempGetPr[i] = x[i];
  }
  tempGetPr = mxGetPr (mx_y);
  for (unsigned int i = 0; i < y.size (); i++) {
    tempGetPr[i] = y[i];
  }
  tempGetPr = mxGetPr (mx_refmatrix);
  for (unsigned int i = 0; i < refmatrix.size (); i++) {
    tempGetPr[i] = refmatrix[i];
  }
  prhs[1] = mx_x;
  prhs[2] = mx_y;
  prhs[0] = mx_refmatrix;
  mexCallMATLAB (2, plhs, 3, prhs, "map2pix");
  tempGetPr = mxGetPr (plhs[1]);
  for (unsigned int i = 0; i < x.size (); i++) {
    xpix[i] = tempGetPr[i] - 1;
  }
  tempGetPr = mxGetPr (plhs[0]);
  for (unsigned int i = 0; i < y.size (); i++) {
    ypix[i] = tempGetPr[i] - 1;
  }
  mxDestroyArray (mx_x);
  mxDestroyArray (mx_y);

  vector < double >estcircle;
  CppCircleFitting (xpix, ypix, estcircle);
  if (estcircle.size () == 0) {
#ifdef DEBUG
    mexPrintf ("CppDetEstCircle ==> CppCircleFitting return empty!\n");
#endif
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    iterationdata.resize (4, 0.0);
    iterationdata[0] = 0.0;
    iterationdata[1] = mxGetNaN ();
    iterationdata[2] = mxGetNaN ();
    iterationdata[3] = static_cast < double >(x.size ());
    ArcInfo.clear ();
    ArcInfo.resize (3, 0.0);
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return true;
  }
  if (estcircle[2] < 0) {
#ifdef DEBUG
    mexPrintf ("CppDetEstCircle ==> CppCircleFitting return negative!\n");
#endif
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    iterationdata.resize (4, 0.0);
    iterationdata[0] = 0.0;
    iterationdata[1] = mxGetNaN ();
    iterationdata[2] = mxGetNaN ();
    iterationdata[3] = static_cast < double >(x.size ());
    ArcInfo.clear ();
    ArcInfo.resize (3, 0.0);
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return true;
  }
  vector < double >precircle (3, mxGetInf ());
  vector < bool > ROIimage (img.size ());
  vector < double >ROIxpix, ROIypix;
  vector < unsigned int >inputImage (img.size ());
  vector < unsigned int >edgeImage (img.size ());
  vector < unsigned int >HTrow, HTcol, HTr, HTpeak;
  vector < double >zeros (img.size (), 0.0);
  vector < double >finalHTcircle, allRsigma;
  unsigned int iterativecount = 0;
  bool fitflag = true;
  double centerchange, radiuschange, finalRsigma;
  transform (img.begin (), img.end (), zeros.begin (), ROIimage.begin (),
             std::not_equal_to < double >());
  centerchange =
    sqrt ((estcircle[0] - precircle[0]) * (estcircle[0] - precircle[0]) +
          (estcircle[1] - precircle[1]) * (estcircle[1] - precircle[1]));
  radiuschange = fabs (estcircle[2] - precircle[2]);
  while (centerchange > epsion / cellsize || radiuschange > epsion / cellsize) {
    // In this while loop, estcircle and precircle are both in unit of pixel.

    // initially detect circle by Hough Transform.
    inputImage.clear ();
    inputImage.resize (img.size (), 0);
    transform (img.begin (), img.end (), ROIimage.begin (),
               inputImage.begin (), std::multiplies < unsigned int >());
    //int debugcount=0;
    //for (unsigned int i=0; i<img.size(); i++)
    //{
    //      if ( (img[i]!=0) && ROIimage[i] )
    //      {
    //              inputImage[i]=img[i];
    //              debugcount++;
    //      }
    //}
    HTrow.clear ();
    HTcol.clear ();
    HTr.clear ();
    HTpeak.clear ();
    if (!
        (CppIterCHT
         (inputImage, dim_img, maxR, edgeImage, dim_img, HTrow, HTcol, HTr,
          HTpeak)
)) {
#ifdef MATLABPRINT
      mexPrintf ("CppDetEstCircle ==> calling CppIterCHT failed!\n");
#endif
      return false;
    }
    if (HTrow.size () == 0) {
      // no circle detected by CHT
      fitflag = false;
      break;
    }
    // select one circle from the above derived by CHT. 
    finalHTcircle.clear ();
    allRsigma.clear ();
    finalRsigma =
      CppSelectHTCircle (edgeImage, dim_img, HTrow, HTcol, HTr, finalHTcircle,
                         allRsigma);
    if (finalRsigma < 0) {
#ifdef MATLABPRINT
      mexPrintf ("CppDetEstCircle ==> calling CppSelectHTCircle failed!\n");
#endif
      return false;
    }
    // mark ROI
    ROIimage.clear ();
    if (!
        (CppMarkROI
         (edgeImage, dim_img, finalHTcircle, xpix, ypix, sigmacoef,
          finalRsigma, ROIimage, ROIxpix, ROIypix)
)) {
#ifdef MATLABPRINT
      mexPrintf ("CppDetEstCircle ==> calling CppMarkROI failed!\n");
#endif
      return false;
    }

    if (ROIxpix.size () < minnumfit) {
#ifdef DEBUG
      mexPrintf
        ("CppDetEstCircle ==> less than minnumfit points used to fit a circle!\n");
#endif
      fitflag = false;
      break;
    }
    precircle.clear ();
    precircle.resize (estcircle.size (), 0.0);
    copy (estcircle.begin (), estcircle.end (), precircle.begin ());
    // fit circles using points in ROI
    CppCircleFitting (ROIxpix, ROIypix, estcircle);
    if (estcircle.size () == 0) {
#ifdef DEBUG
      mexPrintf ("CppDetEstCircle ==> CppCircleFitting return empty!\n");
#endif
      fitflag = false;
      break;
    }
    if (estcircle[2] < 0) {
#ifdef DEBUG
      mexPrintf ("CppDetEstCircle ==> CppCircleFitting return negative!\n");
#endif
      fitflag = false;
      break;
    }
    // calculate change compared with previous circle
    centerchange =
      sqrt ((estcircle[0] - precircle[0]) * (estcircle[0] - precircle[0]) +
            (estcircle[1] - precircle[1]) * (estcircle[1] - precircle[1]));
    radiuschange = fabs (estcircle[2] - precircle[2]);
    iterativecount += 1;

    if (iterativecount == maxIter) {
      fitflag = true;
      break;
    }

  }

  // Now, we begin to check if estcircle(detectedcircle) is derived in while loop and if the derived is valid. 
  // We check it from 3 aspects. 

  // 1st check: whether circle is derived, see if fitflag is true
  if (!fitflag) {
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    iterationdata.resize (4, 0.0);
    iterationdata[0] = static_cast < double >(iterativecount);
    iterationdata[1] = centerchange * cellsize;
    iterationdata[2] = radiuschange * cellsize;
    iterationdata[3] = static_cast < double >(ROIxpix.size ());
    ArcInfo.clear ();
    ArcInfo.resize (3, 0.0);
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return true;
  }
  //2nd check: 
  //see if the detectedcircle(or estcircle) locates within point
  //cloud of trunk, if true, this horizontal point cloud section is
  //unqualified, discard the detectedcircle. If in the 3*3 window
  //centered at detectedcircle point density in every cell is greater
  //than 1, we think the circle center locating within trunk. 
  double ptsdensity;
  ptsdensity =
    CppNeighborPtsDensity (img, dim_img, 3, estcircle[0], estcircle[1]);
  if (ptsdensity < 0) {
#ifdef MATLABPRINT
    mexPrintf ("CppDetEstCircle ==> calling CppNeighborPtsDensity failed!\n");
#endif
    return false;
  }
  if (mxIsInf (ptsdensity)) {
    // If ptsdensity is Inf, the derived center locates outside the rasterized image.

    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    detectedcircle.resize (3, 0.0);
    mapfinalHTcircle.resize (3, 0.0);
    prhs[0] = mx_refmatrix;
    prhs[1] = mxCreateDoubleMatrix (2, 1, mxREAL);
    prhs[2] = mxCreateDoubleMatrix (2, 1, mxREAL);
    tempGetPr = mxGetPr (prhs[1]);
    tempGetPr[0] = estcircle[0] + 1;
    tempGetPr[1] = finalHTcircle[0] + 1;
    tempGetPr = mxGetPr (prhs[2]);
    tempGetPr[0] = estcircle[1] + 1;
    tempGetPr[1] = finalHTcircle[1] + 1;
    mexCallMATLAB (2, plhs, 3, prhs, "pix2map");
    tempGetPr = mxGetPr (plhs[0]);      //xc
    detectedcircle[1] = tempGetPr[0];
    mapfinalHTcircle[1] = tempGetPr[1]; // xc
    tempGetPr = mxGetPr (plhs[1]);      //yc
    detectedcircle[0] = tempGetPr[0];
    mapfinalHTcircle[0] = tempGetPr[1]; // yc
    detectedcircle[2] = estcircle[2] * cellsize;
    mapfinalHTcircle[2] = finalHTcircle[2] * cellsize;  // r
    mxDestroyArray (prhs[1]);
    mxDestroyArray (prhs[2]);
    mxDestroyArray (plhs[0]);
    mxDestroyArray (plhs[1]);

    /*detectedcircle.assign(estcircle.begin(), estcircle.end());
       mapfinalHTcircle.assign(finalHTcircle.begin(), finalHTcircle.end()); */

    iterationdata.clear ();
    iterationdata.resize (4, 0.0);
    iterationdata[0] = static_cast < double >(iterativecount);
    iterationdata[1] = mxGetNaN ();
    iterationdata[2] = mxGetNaN ();
    iterationdata[3] = static_cast < double >(ROIxpix.size ());
    ArcInfo.clear ();
    ArcInfo.resize (3, 0.0);
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return true;
  } else if (ptsdensity > 1) {
    // If ptsdensity is greater than 1, the derived center is on the trunk, not valid!
    detectedcircle.clear ();
    mapfinalHTcircle.clear ();
    iterationdata.clear ();
    iterationdata.resize (4, 0.0);
    iterationdata[0] = static_cast < double >(iterativecount);
    iterationdata[1] = centerchange * cellsize;
    iterationdata[2] = radiuschange * cellsize;
    iterationdata[3] = static_cast < double >(ROIxpix.size ());
    ArcInfo.clear ();
    ArcInfo.resize (3, 0.0);
    finalx.clear ();
    finaly.clear ();
    DebugInfo.clear ();
    return true;
  }
  // 3rd check: Iteration (while loop) ends possibly without getting right circle but due to reaching maximum iteration count or failed HT.
  // So here the estcircle derived from while loop is checked whether satisfying the right circle condition. 
  if (iterativecount == maxIter) {
    if (centerchange > epsion / cellsize || radiuschange > epsion / cellsize) {
      detectedcircle.clear ();
      mapfinalHTcircle.clear ();
      iterationdata.clear ();
      iterationdata.resize (4, 0.0);
      iterationdata[0] = static_cast < double >(maxIter);
      iterationdata[1] = centerchange * cellsize;
      iterationdata[2] = radiuschange * cellsize;
      iterationdata[3] = static_cast < double >(ROIxpix.size ());
      ArcInfo.clear ();
      ArcInfo.resize (3, 0.0);
      finalx.clear ();
      finaly.clear ();
      DebugInfo.clear ();
      return true;
    }
  }
  //After all checked, we can output the valid derived circle.
  detectedcircle.clear ();
  mapfinalHTcircle.clear ();
  detectedcircle.resize (3, 0.0);
  mapfinalHTcircle.resize (3, 0.0);
  prhs[0] = mx_refmatrix;
  prhs[1] = mxCreateDoubleMatrix (2, 1, mxREAL);
  prhs[2] = mxCreateDoubleMatrix (2, 1, mxREAL);
  tempGetPr = mxGetPr (prhs[1]);
  tempGetPr[0] = estcircle[0] + 1;
  tempGetPr[1] = finalHTcircle[0] + 1;
  tempGetPr = mxGetPr (prhs[2]);
  tempGetPr[0] = estcircle[1] + 1;
  tempGetPr[1] = finalHTcircle[1] + 1;
  mexCallMATLAB (2, plhs, 3, prhs, "pix2map");
  tempGetPr = mxGetPr (plhs[0]);        //xc
  detectedcircle[1] = tempGetPr[0];
  mapfinalHTcircle[1] = tempGetPr[1];   // xc
  tempGetPr = mxGetPr (plhs[1]);        //yc
  detectedcircle[0] = tempGetPr[0];
  mapfinalHTcircle[0] = tempGetPr[1];   // yc
  detectedcircle[2] = estcircle[2] * cellsize;
  mapfinalHTcircle[2] = finalHTcircle[2] * cellsize;    // r
  mxDestroyArray (prhs[1]);
  mxDestroyArray (prhs[2]);
  mxDestroyArray (plhs[0]);
  mxDestroyArray (plhs[1]);

  // convert ROIxpix, ROIypix to finalx, finaly
  finalx.clear ();
  finalx.resize (ROIxpix.size ());
  finaly.clear ();
  finaly.resize (ROIypix.size ());
  prhs[0] = mx_refmatrix;
  prhs[1] = mxCreateDoubleMatrix (ROIypix.size (), 1, mxREAL);
  prhs[2] = mxCreateDoubleMatrix (ROIxpix.size (), 1, mxREAL);
  tempGetPr = mxGetPr (prhs[1]);
  for (unsigned int i = 0; i < ROIypix.size (); i++) {
    tempGetPr[i] = ROIypix[i] + 1;
  }
  tempGetPr = mxGetPr (prhs[2]);
  for (unsigned int i = 0; i < ROIxpix.size (); i++) {
    tempGetPr[i] = ROIxpix[i] + 1;
  }
  mexCallMATLAB (2, plhs, 3, prhs, "pix2map");
  tempGetPr = mxGetPr (plhs[0]);        //finalx
  for (unsigned int i = 0; i < ROIxpix.size (); i++) {
    finalx[i] = tempGetPr[i];
  }
  tempGetPr = mxGetPr (plhs[1]);        //finaly
  for (unsigned int i = 0; i < ROIypix.size (); i++) {
    finaly[i] = tempGetPr[i];
  }
  mxDestroyArray (prhs[1]);
  mxDestroyArray (prhs[2]);
  mxDestroyArray (plhs[0]);
  mxDestroyArray (plhs[1]);
  mxDestroyArray (mx_refmatrix);

  iterationdata.clear ();
  iterationdata.resize (4, 0.0);
  iterationdata[0] = static_cast < double >(iterativecount);
  iterationdata[1] = centerchange * cellsize;
  iterationdata[2] = radiuschange * cellsize;
  iterationdata[3] = static_cast < double >(ROIxpix.size ());
  ArcInfo.clear ();
  if (!CppArcInfo (ROIxpix, ROIypix, estcircle, ArcInfo)) {
#ifdef MATLABPRINT
    mexPrintf ("CppDetEstCircle ==> calling CppArcInfo failed!\n");
#endif
    return false;
  }
  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  // Because when rasterizing point clouds
  // in the function CppGridPts the center of the first pixel, 
  // i.e. the pixel at [1,1] locates at (minx, maxy), 
  // we have to transform the angle in i-j(raster) coordinate system
  // to x-y(point clouds) coordinate system. 
  // In x-y coordinate system, y axis points to north, 
  // so angle is presented in counterclockwise. 
  // In contrast, in i-j coordinate system, 
  // i axis (i.e. y axis in raster) points to south, 
  // so angle is presented in clockwise.
  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  ArcInfo[0] = 2 * PI - ArcInfo[0];
  ArcInfo[1] = 2 * PI - ArcInfo[1];

  DebugInfo.clear ();
  DebugInfo.resize (1);
  DebugInfo[0] = finalRsigma * cellsize;

#ifdef DEBUG
  mexPrintf ("CppDetEstCircle ==> finally points used to fit a circle: %d!\n",
             ROIxpix.size ());
#endif

  return true;
}