// Derivative-of-Gaussian (gradient) operator.
cv::Mat ImageFilter::DerivativeOfGaussianOperator::operator()(const cv::Mat& img, const std::size_t apertureSize, const double sigma) const
{
	const int halfApertureSize = (int)apertureSize / 2;

#if 0
	cv::Mat Gx(apertureSize, apertureSize, CV_64F), Gy(apertureSize, apertureSize, CV_64F);
	{
		//const double sigma2 = sigma * sigma, _2_sigma2 = 2.0 * sigma2, _2_pi_sigma4 = M_PI * _2_sigma2 * sigma2;
		const double sigma2 = sigma * sigma, _2_sigma2 = 2.0 * sigma2;
		for (int y = -halfApertureSize, yy = 0; y <= halfApertureSize; ++y, ++yy)
			for (int x = -halfApertureSize, xx = 0; x <= halfApertureSize; ++x, ++xx)
			{
				//const double factor = std::exp(-(double(x)*double(x) + double(y)*double(y)) / _2_sigma2) / _2_pi_sigma4;
				const double exp = std::exp(-(double(x)*double(x) + double(y)*double(y)) / _2_sigma2);
				// TODO [check] >> x- & y-axis derivative.
				//Gx.at<double>(yy, xx) = -double(x) * factor;
				//Gy.at<double>(yy, xx) = -double(y) * factor;
				Gx.at<double>(yy, xx) = -double(x) * exp;
				Gy.at<double>(yy, xx) = -double(y) * exp;
			}

		// Make sure that the sum (or average) of all elements of the kernel has to be zero (similar to the Laplace kernel) so that the convolution result of a homogeneous regions is always zero.
		//	REF [site] >> http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html
		Gx -= cv::sum(Gx) / ((double)apertureSize * (double)apertureSize);
		Gy -= cv::sum(Gy) / ((double)apertureSize * (double)apertureSize);
	}
#else
	// If a kernel has the same size in x- and y-directions.

	cv::Mat Gx(apertureSize, apertureSize, CV_64F);
	{
		//const double sigma2 = sigma * sigma, _2_sigma2 = 2.0 * sigma2, _2_pi_sigma4 = M_PI * _2_sigma2 * sigma2;
		const double sigma2 = sigma * sigma, _2_sigma2 = 2.0 * sigma2;
		for (int y = -halfApertureSize, yy = 0; y <= halfApertureSize; ++y, ++yy)
			for (int x = -halfApertureSize, xx = 0; x <= halfApertureSize; ++x, ++xx)
			{
				//Gx.at<double>(yy, xx) = -double(x) * std::exp(-(double(x)*double(x) + double(y)*double(y)) / _2_sigma2) / _2_pi_sigma4;
				Gx.at<double>(yy, xx) = -double(x) * std::exp(-(double(x)*double(x) + double(y)*double(y)) / _2_sigma2);
			}

		// Make sure that the sum (or average) of all elements of the kernel has to be zero (similar to the Laplace kernel) so that the convolution result of a homogeneous regions is always zero.
		//	REF [site] >> http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html
		Gx -= cv::sum(Gx) / ((double)apertureSize * (double)apertureSize);
	}

	cv::Mat Gy;
	cv::transpose(Gx, Gy);
#endif

	cv::Mat Fx, Fy;
	cv::filter2D(img, Fx, CV_64F, Gx, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
	cv::filter2D(img, Fy, CV_64F, Gy, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);

	cv::Mat gradient;
	cv::magnitude(Fx, Fy, gradient);

	return gradient;
}
Example #2
0
/*!
  Computes the first unpolarized moment
  
  \f[
  {\cal O}_{14} = \overline{q} \left[ \gamma_1 
  \stackrel{\displaystyle \leftrightarrow}{D}_4
  +\gamma_4 
  \stackrel{\displaystyle \leftrightarrow}{D}_1
  \right] q
  \f]
  
  with polarized projector
*/
void AlgNuc3pt::calc_EnergyMomentum(const ThreeMom& mom)
{
  OpenFile(); 
  Fprintf(fp,"The next is: Energy momentum k4 + 4k\n");
  CloseFile();
  for ( int n = 0; n < num_qprop; n++ ) {
    for (int i(X);i<4;i++){
      DIR d = DIR(i) ;
      Gamma Gx(d);
      Gamma Gt(T);
      Derivative Der_t(T);
      Derivative Der_x(d);
      
      Nuc3ptStru Xq_xt(mom,Gx, Der_t);
      Xq_xt.Calc3pt(*u_s_prop, *q_prop[n]);
      Xq_xt.Calc3pt(*d_s_prop, *q_prop[n]);
      
      Nuc3ptStru Xq_tx(mom,Gt,Der_x);
      Xq_tx.Calc3pt(*u_s_prop, *q_prop[n]);
      Xq_tx.Calc3pt(*d_s_prop, *q_prop[n]);
      
      Xq_xt += Xq_tx ;
      OpenFile(); 
      Xq_xt.Print(fp) ; 
      CloseFile();
    }
  }
}
Point calculateBSpline(float t, const Point& p1, const Point& p2, const Point& p3, const Point& p4)
{
	Point result;
	Vec4f T(t*t*t, t*t, t, 1);
	Mat4f M(-1, 3, -3, 1,
		3, -6, 3, 0,
		-3, 0, 3, 0,
		1, 4, 1, 0);
	Vec4f Gx(p1.x, p2.x, p3.x, p4.x);
	Vec4f Gy(p1.y, p2.y, p3.y, p4.y);

	result.x = (T*M)*Gx / 6;
	result.y = (T*M)*Gy / 6;
	return result;
}
Example #4
0
// ABGR
int value_to_color_888(float v, float max)
{
  int s;
  int R;
  int G;
  int B;

  float fact = max;

  v = v / fact;
  B = (int)255. * Bx(v);
  G = (int)255. * Gx(v);
  R = (int)255. * Rx(v);
  s = (R & 0xFF) + ((G & 0xFF) << 8) + ((B & 0xFF) << 16);
  return s;
}
Example #5
0
// Normalises a value v in 0. and 1. and converts that to a rgb 565 short int
int value_to_color_565(float v, float max)
{
  int s;
  int R;
  int G;
  int B;

  float fact = max;

  v = v / fact;
  B = (int)31. * Bx(v);
  G = (int)63. * Gx(v);
  R = (int)31. * Rx(v);
  s = (R % 32) + ((G % 64) << 5) + ((B % 32) << 11);
//  if (v == 1.)
  //  s = 0xFE00;
  //printf("vla=%f, max=%f\n", v, max);
  return s;
}
/*static*/ void ImageFilter::computeDerivativesOfImage(const cv::Mat& img, const std::size_t apertureSize, const double sigma, cv::Mat& Fx, cv::Mat& Fy, cv::Mat& Fxx, cv::Mat& Fyy, cv::Mat& Fxy)
{
	// Compute derivatives wrt xy-coordinate system.
	cv::Mat Gx(apertureSize, apertureSize, CV_64F), Gy(apertureSize, apertureSize, CV_64F);
	cv::Mat Gxx(apertureSize, apertureSize, CV_64F), Gyy(apertureSize, apertureSize, CV_64F), Gxy(apertureSize, apertureSize, CV_64F);
	DerivativesOfGaussian::getFirstOrderDerivatives(apertureSize, sigma, Gx, Gy);
	DerivativesOfGaussian::getSecondOrderDerivatives(apertureSize, sigma, Gxx, Gyy, Gxy);

	// Make sure that the sum (or average) of all elements of the kernel has to be zero (similar to the Laplace kernel) so that the convolution result of a homogeneous regions is always zero.
	//	REF [site] >> http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html
	const double kernelArea = (double)apertureSize * (double)apertureSize;
	Gx -= cv::sum(Gx) / kernelArea;
	Gy -= cv::sum(Gy) / kernelArea;
	Gxx -= cv::sum(Gxx) / kernelArea;
	Gyy -= cv::sum(Gyy) / kernelArea;
	Gxy -= cv::sum(Gxy) / kernelArea;

	// Compute Fx, Fy, Fxx, Fyy, Fxy.
	cv::filter2D(img, Fx, CV_64F, Gx, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
	cv::filter2D(img, Fy, CV_64F, Gy, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
	cv::filter2D(img, Fxx, CV_64F, Gxx, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
	cv::filter2D(img, Fyy, CV_64F, Gyy, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
	cv::filter2D(img, Fxy, CV_64F, Gxy, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
}
Example #7
0
	0,		0,		0,		0,		 0, 	  0,
	0,		0,		0,		0,		 0, 	  0,
	0,		0,		0,		0,		 0, 	  0,
	0,		0,		0,		0,		 0, 	  0,
	0,		0,		0,		0,		 0, 	  0
};

/* This is used to play single notes for the TMS3615/TMS3617 */
static int tune4[13*6] = {
/*	16'     8'      5 1/3'  4'      2 2/3'  2'      */
	B(0),	B(1),	Dx(2),	B(2),	Dx(3),	B(3),
	C(1),	C(2),	E(2),	C(3),	E(3),	C(4),
	Cx(1),	Cx(2),	F(2),	Cx(3),	F(3),	Cx(4),
	D(1),	D(2),	Fx(2),	D(3),	Fx(3),	D(4),
	Dx(1),	Dx(2),	G(2),	Dx(3),	G(3),	Dx(4),
	E(1),	E(2),	Gx(2),	E(3),	Gx(3),	E(4),
	F(1),	F(2),	A(2),	F(3),	A(3),	F(4),
	Fx(1),	Fx(2),	Ax(2),	Fx(3),	Ax(3),	Fx(4),
	G(1),	G(2),	B(2),	G(3),	B(3),	G(4),
	Gx(1),	Gx(2),	C(3),	Gx(3),	C(4),	Gx(4),
	A(1),	A(2),	Cx(3),	A(3),	Cx(4),	A(4),
	Ax(1),	Ax(2),	D(3),	Ax(3),	D(4),	Ax(4),
	B(1),	B(2),	Dx(3),	B(3),	Dx(4),	B(4)
};

static int *tunes[] = {NULL,tune1,tune2,tune3,tune4};

#define DECAY(voice)											\
	if( tms->vol[voice] > VMIN )								\
	{															\
		/* decay of first voice */								\
Example #8
0
int
PFEMElement2D::update()
{
    // get nodal coordinates
    double x[3], y[3];
    for(int a=0; a<3; a++) {
        const Vector& coord = nodes[2*a]->getCrds();
        const Vector& disp = nodes[2*a]->getTrialDisp();
        x[a] = coord(0) + disp(0);
        y[a] = coord(1) + disp(1);
    }

    // get c and d
    double cc[3], dd[3];
    cc[0] = y[1]-y[2];
    dd[0] = x[2]-x[1];
    cc[1] = y[2]-y[0];
    dd[1] = x[0]-x[2];
    cc[2] = y[0]-y[1];
    dd[2] = x[1]-x[0];

    // get Jacobi
    double J = cc[0]*dd[1]-dd[0]*cc[1];

    if(fabs(J)<1e-15) {
        opserr<<"WARNING: element area is nearly zero";
        opserr<<" -- PFEMElement2D::update\n";
	for (int i=0; i<3; i++) {
	    opserr<<"node "<<ntags[2*i]<<"\n";
	    opserr<<"x = "<<x[i]<<" , y = "<<y[i]<<"\n";
	}

        return -1;
    }

    // get M
    M = rho*J*thickness/6.0;
    Mp = (kappa<=0? 0.0 : J*thickness/kappa/24.0);
    double Mb = 9.*rho*J*thickness/40.0;

    // get Km
    Km.Zero();
    double fact = mu*thickness/(6.*J);
    for (int a=0; a<3; a++) {
	for (int b=0; b<3; b++) {
	    Km(2*a,2*b) = fact*(4*cc[a]*cc[b]+3*dd[a]*dd[b]); // Kxx
	    Km(2*a,2*b+1) = fact*(3*dd[a]*cc[b]-2*cc[a]*dd[b]); // Kxy
	    Km(2*a+1,2*b) = fact*(3*cc[a]*dd[b]-2*dd[a]*cc[b]); // Kyx
	    Km(2*a+1,2*b+1) = fact*(3*cc[a]*cc[b]+4*dd[a]*dd[b]); // Kyy
	}
    }

    // get Kb
    Matrix Kb(2,2);
    fact = 27.*mu*thickness/(40.*J);
    double cc2 = 0., dd2 = 0., cd2 = 0.;
    for(int a=0; a<3; a++) {
	cc2 += cc[a]*cc[a];
	dd2 += dd[a]*dd[a];
	cd2 += cc[a]*dd[a];
    }
    Kb(0,0) = fact*(4*cc2+3*dd2); // Kxx
    Kb(0,1) = fact*cd2; // Kxy
    Kb(1,0) = fact*cd2; // Kyx
    Kb(1,1) = fact*(3*cc2+4*dd2); // Kyy

    // get Gx and Gy
    Gx.Zero(); Gy.Zero();
    fact = thickness/6.0;
    for (int a=0; a<3; a++) {
	Gx(a) = cc[a]*fact;
	Gy(a) = dd[a]*fact;
    }

    // get Gb
    Matrix Gb(2,3);
    fact = -9.*thickness/40.0;
    for (int a=0; a<3; a++) {
	Gb(0,a) = cc[a]*fact;
	Gb(1,a) = dd[a]*fact;
    }

    // get S
    S.Zero();
    if (ops_Dt > 0) {
	Kb(0,0) += Mb/ops_Dt;
	Kb(1,1) += Mb/ops_Dt;
    }
    if (Kb(0,0)!=0 && Kb(1,1)!=0) {
	this->inverse(Kb);
    }
    S.addMatrixTripleProduct(0.0, Gb, Kb, 1);

    // get F
    F.Zero();
    fact = rho*J*thickness/6.0;
    F(0) = fact*b1;
    F(1) = fact*b2;

    // get Fb
    Vector Fb(2);
    fact = 9.*rho*J*thickness/40.;
    Fb(0) = fact*b1;
    Fb(1) = fact*b2;

    // get Fp
    Fp.Zero();
    Fp.addMatrixTransposeVector(0.0, Gb, Kb*Fb, -1);

    return 0;
}