コード例 #1
0
    void prod_impl(const viennacl::toeplitz_matrix<SCALARTYPE, ALIGNMENT> & mat,
                   const viennacl::vector_base<SCALARTYPE> & vec,
                         viennacl::vector_base<SCALARTYPE> & result)
    {
      assert(mat.size1() == result.size());
      assert(mat.size2() == vec.size());

      viennacl::vector<SCALARTYPE> tmp(vec.size() * 4); tmp.clear();
      viennacl::vector<SCALARTYPE> tmp2(vec.size() * 4);

      viennacl::vector<SCALARTYPE> tep(mat.elements().size() * 2);
      viennacl::linalg::real_to_complex(mat.elements(), tep, mat.elements().size());



      viennacl::copy(vec.begin(), vec.end(), tmp.begin());
      viennacl::linalg::real_to_complex(tmp, tmp2, vec.size() * 2);
      viennacl::linalg::convolve(tep, tmp2, tmp);
      viennacl::linalg::complex_to_real(tmp, tmp2, vec.size() * 2);
      viennacl::copy(tmp2.begin(), tmp2.begin() + static_cast<vcl_ptrdiff_t>(vec.size()), result.begin());
    }
コード例 #2
0
ファイル: SIFT.cpp プロジェクト: rayz0620/CVTraining2013Azure
cv::Mat SIFT::Less( Mat src,float num )
{
	CvSize size=src.size();
	Mat tep(size.height,size.width,CV_32F);
	for(int i=0;i<size.height;i++)
	{
		for(int j=0;j<size.width;j++)
		{
			if(src.at<float>(i,j)<=num)
			{
				tep.at<float>(i,j)=1;
			}
			else
			{
				tep.at<float>(i,j)=0;
			}

		}
	}
	return tep;
}
コード例 #3
0
void prod_impl(const viennacl::toeplitz_matrix<SCALARTYPE, ALIGNMENT> & mat,
               const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec,
               viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & result)
{
    assert(mat.size1() == result.size());
    assert(mat.size2() == vec.size());

    viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> tmp(vec.size() * 4);
    tmp.clear();
    viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> tmp2(vec.size() * 4);

    viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> tep(mat.elements().size() * 2);
    viennacl::detail::fft::real_to_complex(mat.elements(), tep, mat.elements().size());



    copy(vec, tmp);
    viennacl::detail::fft::real_to_complex(tmp, tmp2, vec.size() * 2);
    viennacl::linalg::convolve(tep, tmp2, tmp);
    viennacl::detail::fft::complex_to_real(tmp, tmp2, vec.size() * 2);
    copy(tmp2.begin(), tmp2.begin() + vec.size(), result.begin());
}
コード例 #4
0
ファイル: SIFT.cpp プロジェクト: rayz0620/CVTraining2013Azure
cv::Mat SIFT::sp_normalize_sift_arr( Mat sift_arr,float threshold )
{
	Mat siftlen=sp_normalize_sift_len(sift_arr);
	Mat normalize_ind1=compare(siftlen,threshold);
	Mat normalize_ind2=change(normalize_ind1);

	Mat sift_arr_hcontrast=search(sift_arr,normalize_ind1);
	sift_arr_hcontrast=sift_arr_hcontrast/repmat(search(siftlen,normalize_ind1),1,sift_arr.cols);//此处应为点除

	Mat sift_arr_lcontrast=search(sift_arr,normalize_ind2);
	sift_arr_lcontrast=sift_arr_lcontrast/threshold;

	sift_arr_hcontrast= suppresss(sift_arr_hcontrast,0.2);
	sift_arr_lcontrast= suppresss(sift_arr_lcontrast,0.2);

	Mat tep(sift_arr_hcontrast.rows,1,CV_32F);
	sqrt(sum_row(square(sift_arr_hcontrast)),tep);
	sift_arr_hcontrast = sift_arr_hcontrast /repmat(tep, 1,sift_arr.cols);

	assign(sift_arr,normalize_ind1,sift_arr_hcontrast);
	assign(sift_arr,normalize_ind2,sift_arr_lcontrast);

	return sift_arr;
}
コード例 #5
0
ファイル: SIFT.cpp プロジェクト: rayz0620/CVTraining2013Azure
cv::Mat SIFT::sp_find_sift_grid( Mat I,Mat gridX,Mat gridY,int patchSize, float sigma_edge )
{
	int num_angles=8;
	float num_bins=4;
	int num_samples=num_bins*num_bins;
	int alpha = 9;

	//此处需要判断总共传入多少个变量,如果变量数小于5,就把sigma_edge设置为1
	float angle_step=2*pi/num_angles;

	//初始化angles 为一个一维矩阵从0到2*pi;间隔为angle_step
	Mat angles=create(0,2*pi,angle_step);
	angles=deleteO(angles); //删除最后一个元素

	CvSize size=I.size();
	//int hgt=size.height;
	//int wid=size.width;

	int num_patches=gridX.total();//计算gridX总共有多少个元素

	Mat sift_arr=Mat::zeros(num_patches,num_samples*num_angles,CV_32F);

	//计算滤波算子
	int  f_wid = 4 * ceil(sigma_edge) + 1;
	Mat G=gaussian(f_wid,sigma_edge);

	Mat GX=gradientX(G);
	Mat GY=gradientY(G);


	GX=GX*2/totalSumO(GX);
	GY=GY*2/totalSumO(GY);



	Mat I_X(I.rows,I.cols,CV_32F);
	I_X=filter2(GX,I);              //因为I,图片读入不同,所以I_X不同,与I有关的均布相同,但是,都正确


	Mat I_Y(I.rows,I.cols,CV_32F);
	I_Y=filter2(GY,I);

	Mat T(I_X.rows,I_X.cols,CV_32F);
	add(I_X.mul(I_X),I_Y.mul(I_Y),T);
	Mat I_mag(I_X.rows,I_X.cols,CV_32F);
	sqrt(T,I_mag);
	Mat I_theta=matan2(I_Y,I_X);

	Mat interval=create(2/num_bins,2,2/num_bins);
	interval-=(1/num_bins+1);

	Mat sample_x=meshgrid_X(interval,interval);


	Mat sample_y=meshgrid_Y(interval,interval);

	sample_x=reshapeX(sample_x);//变为一个1维矩阵

	sample_y=reshapeX(sample_y);

	Mat I_orientation[8] = {Mat::zeros(size,CV_32F)};
	for(int i=0;i<8;i++)
	{
		I_orientation[i] = Mat::zeros(size,CV_32F);
	}
	float *pt=angles.ptr<float>(0);

	for(int a=0;a<num_angles;a++)
	{
		Mat tep1=mcos(I_theta-pt[a]);//cos
		//cout<<tep1.at<float>(0,1)<<endl;
		Mat tep(tep1.rows,tep1.cols,CV_32F);
		pow(tep1,alpha,tep);
		tep=compareB(tep,0);
		I_orientation[a]=tep.mul(I_mag);
	}

	for(int i=0;i<num_patches;i++)
	{

		double r=patchSize/2;
		float l=(float)(i/gridX.rows);
		float m=i%gridX.rows;
		float cx=gridX.at<float>(m,l)+r-0.5;
		float cy=gridY.at<float>(m,l)+r-0.5;

		Mat sample_x_t=Add(sample_x*r,cx);
		Mat sample_y_t=Add(sample_y*r,cy);
		float *pt1=sample_y_t.ptr<float>(0);
		float sample_res=pt1[1]-pt1[0];

// 		int c=(int)i/gridX.rows;
// 		float *ptc1=gridX.ptr<float>(c);
// 		int x_lo=ptc1[i%gridX.rows];

		int x_lo = gridX.at<float>(i % gridX.rows, i / gridX.rows);
		int x_hi=patchSize+x_lo-1;
/*		float *ptc2=gridY.ptr<float>(c);*/


		int y_lo=gridY.at<float>(i % gridY.rows, i / gridY.rows);
		int y_hi=y_lo+patchSize-1;

		Mat A=create(x_lo,x_hi,1);
		Mat B=create(y_lo,y_hi,1);


		Mat sample_px=meshgrid_X(A,B);
		Mat sample_py=meshgrid_Y(A,B);

		int num_pix = sample_px.total();//计算sample_px元素总数
		sample_px=reshapeY(sample_px);
		sample_py=reshapeY(sample_py);


		Mat dist_px=abs(repmat(sample_px,1,num_samples)-repmat(sample_x_t,num_pix,1));
		Mat dist_py=abs(repmat(sample_py,1,num_samples)-repmat(sample_y_t,num_pix,1));


		Mat weights_x=dist_px/sample_res;
		Mat weights_x_l=Less(weights_x,1);
		weights_x=(1-weights_x).mul(weights_x_l);

		Mat weights_y=dist_py/sample_res;
		Mat weights_y_l=Less(weights_y,1);
		weights_y=(1-weights_y).mul(weights_y_l);
		Mat weights=weights_x.mul(weights_y);

		Mat curr_sift=Mat::zeros(num_angles,num_samples,CV_32F);
		for(int a=0;a<num_angles;a++)
		{
			//Mat I=getNum(I_orientation[a],y_lo,y_hi,x_lo,x_hi);
			Mat I = I_orientation[a](Range(y_lo, y_hi), Range(x_lo, x_hi));
			Mat tep=reshapeY(I);

			// Fill tep with zeros to fit size of weight
			if (tep.cols < weights.cols)
			{
				for (int i = tep.rows; i < weights.rows; i++)
					tep.push_back(0.0f);
			}

			tep=repmat(tep,1,num_samples);
			Mat t=tep.mul(weights);
			Mat ta=sum_every_col(t);
			float *p=ta.ptr<float>(0);
			for(int i=0;i<curr_sift.cols;i++)
			{
				curr_sift.at<float>(a,i)=p[i];
			}

		}
		Mat tp=reshapeX(curr_sift);
		float *p=tp.ptr<float>(0);
		for(int j=0;j<sift_arr.cols;j++)
		{
			sift_arr.at<float>(i,j)=p[j];
		}

	}

	return sift_arr;
}
コード例 #6
0
ファイル: TauContribution_Def.hpp プロジェクト: dlonie/Albany
TauContribution<EvalT, Traits>::
TauContribution(Teuchos::ParameterList& p) :
tauFactor(p.get<std::string>("Tau Contribution Name"),
		 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"))
{
  Teuchos::ParameterList* elmd_list = 
    p.get<Teuchos::ParameterList*>("Parameter List");

  Teuchos::RCP<PHX::DataLayout> vector_dl =
    p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout");
  std::vector<PHX::DataLayout::size_type> dims;
  vector_dl->dimensions(dims);
  numQPs  = dims[1];
  numDims = dims[2];

  Teuchos::RCP<ParamLib> paramLib = 
    p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null);

  std::string type = elmd_list->get("Tau Contribution Type", "Constant");
  if (type == "Constant") {
    is_constant = true;
    constant_value = elmd_list->get("Value", 0.0);

    // Add Trapped Solvent as a Sacado-ized parameter
    new Sacado::ParameterRegistration<EvalT, SPL_Traits>(
	"Tau Contribution", this, paramLib);
  }
  else if (type == "Truncated KL Expansion") {
    is_constant = false;
    PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim>
      fx(p.get<std::string>("QP Coordinate Vector Name"), vector_dl);
    coordVec = fx;
    this->addDependentField(coordVec);

    exp_rf_kl = 
      Teuchos::rcp(new Stokhos::KL::ExponentialRandomField<MeshScalarT>(*elmd_list));
    int num_KL = exp_rf_kl->stochasticDimension();

    // Add KL random variables as Sacado-ized parameters
    rv.resize(num_KL);
    for (int i=0; i<num_KL; i++) {
      std::string ss = Albany::strint("Trapped Solvent KL Random Variable",i);
      new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib);
      rv[i] = elmd_list->get(ss, 0.0);
    }
  }
  else {
	  TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
		       "Invalid Trapped Solvent type " << type);
  } 

  if ( p.isType<std::string>("QP Variable Name") ) {
     Teuchos::RCP<PHX::DataLayout> scalar_dl =
       p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
     PHX::MDField<ScalarT,Cell,QuadPoint>
       tp(p.get<std::string>("QP Variable Name"), scalar_dl);
     Clattice = tp;
     this->addDependentField(Clattice);
     VmPartial = elmd_list->get("Partial Molar Volume Value", 0.0);
     new Sacado::ParameterRegistration<EvalT, SPL_Traits>(
                                 "Partial Molar Volume Value", this, paramLib);

   }
   else {
     VmPartial = 2.0e-6;
   }

  if ( p.isType<std::string>("Diffusion Coefficient Name") ) {
       Teuchos::RCP<PHX::DataLayout> scalar_dl =
         p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
       PHX::MDField<ScalarT,Cell,QuadPoint>
         ap(p.get<std::string>("Diffusion Coefficient Name"), scalar_dl);
       DL = ap;
       this->addDependentField(DL);

  }

 /*
  if ( p.isType<std::string>("Ideal Gas Constant Name") ) {
           Teuchos::RCP<PHX::DataLayout> scalar_dl =
             p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
           PHX::MDField<ScalarT,Cell,QuadPoint>
             idg(p.get<std::string>("Ideal Gas Constant Name"), scalar_dl);
           Rideal = idg;
           this->addDependentField(Rideal);

      }
  */

  if ( p.isType<std::string>("Temperature Name") ) {
         Teuchos::RCP<PHX::DataLayout> scalar_dl =
           p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
         PHX::MDField<ScalarT,Cell,QuadPoint>
           tep(p.get<std::string>("Temperature Name"), scalar_dl);
         temperature = tep;

         Rideal = p.get<RealType>("Ideal Gas Constant", 8.3144621);
         this->addDependentField(temperature);

    }




  this->addEvaluatedField(tauFactor);
  this->setName("Tau Contribution"+PHX::TypeString<EvalT>::value);
}