예제 #1
0
template <typename PointInT, typename IntensityT> void
pcl::tracking::PyramidalKLTTracker<PointInT, IntensityT>::mismatchVector (const Eigen::ArrayXXf& prev,
                                                                   const Eigen::ArrayXXf& prev_grad_x,
                                                                   const Eigen::ArrayXXf& prev_grad_y,
                                                                   const FloatImage& next,
                                                                   const Eigen::Array2i& location,
                                                                   const Eigen::Array4f& weight,
                                                                   Eigen::Array2f &b) const
{
  const int step = next.width;
  b.setZero ();
  for (int y = 0; y < track_height_; y++)
  {
    const float* next_ptr = &(next.points[0]) + (y + location[1])*step + location[0];
    const float* prev_ptr = prev.data () + y*prev.cols ();
    const float* prev_grad_x_ptr = prev_grad_x.data () + y*prev_grad_x.cols ();
    const float* prev_grad_y_ptr = prev_grad_y.data () + y*prev_grad_y.cols ();

    for (int x = 0; x < track_width_; ++x, ++prev_grad_y_ptr, ++prev_grad_x_ptr)
    {
      float diff = next_ptr[x]*weight[0] + next_ptr[x+1]*weight[1]
      + next_ptr[x+step]*weight[2] + next_ptr[x+step+1]*weight[3] - prev_ptr[x];
      b[0] += *prev_grad_x_ptr * diff;
      b[1] += *prev_grad_y_ptr * diff;
    }
  }
}
예제 #2
0
template <typename PointInT, typename IntensityT> void
pcl::tracking::PyramidalKLTTracker<PointInT, IntensityT>::spatialGradient (const FloatImage& img,
                                                                    const FloatImage& grad_x,
                                                                    const FloatImage& grad_y,
                                                                    const Eigen::Array2i& location,
                                                                    const Eigen::Array4f& weight,
                                                                    Eigen::ArrayXXf& win,
                                                                    Eigen::ArrayXXf& grad_x_win,
                                                                    Eigen::ArrayXXf& grad_y_win,
                                                                    Eigen::Array3f &covariance) const
{
  const int step = img.width;
  covariance.setZero ();

  for (int y = 0; y < track_height_; y++)
  {
    const float* img_ptr = &(img.points[0]) + (y + location[1])*step + location[0];
    const float* grad_x_ptr = &(grad_x.points[0]) + (y + location[1])*step + location[0];
    const float* grad_y_ptr = &(grad_y.points[0]) + (y + location[1])*step + location[0];

    float* win_ptr = win.data () + y*win.cols ();
    float* grad_x_win_ptr = grad_x_win.data () + y*grad_x_win.cols ();
    float* grad_y_win_ptr = grad_y_win.data () + y*grad_y_win.cols ();

    for (int x =0; x < track_width_; ++x, ++grad_x_ptr, ++grad_y_ptr)
    {
      *win_ptr++  = img_ptr[x]*weight[0] + img_ptr[x+1]*weight[1] + img_ptr[x+step]*weight[2] + img_ptr[x+step+1]*weight[3];
      float ixval = grad_x_ptr[0]*weight[0] + grad_x_ptr[1]*weight[1] + grad_x_ptr[step]*weight[2] + grad_x_ptr[step+1]*weight[3];
      float iyval = grad_y_ptr[0]*weight[0] + grad_y_ptr[1]*weight[1] + grad_y_ptr[step]*weight[2] + grad_y_ptr[step+1]*weight[3];
      //!!! store those
      *grad_x_win_ptr++ = ixval;
      *grad_y_win_ptr++ = iyval;
      //covariance components
      covariance[0] += ixval*ixval;
      covariance[1] += ixval*iyval;
      covariance[2] += iyval*iyval;
    }
  }
}
예제 #3
0
RepSupernmotif::RepSupernmotif(Eigen::ArrayXXf matALLMotifWeigthed,int nbSupNmotifs,int p_outputOption) {
	// TODO Auto-generated constructor stub

        if((p_outputOption==0)||(p_outputOption==1))//Compute the super n-motifs representation
        {
			int maxDim;
			if(matALLMotifWeigthed.rows()>matALLMotifWeigthed.cols())
			{maxDim=matALLMotifWeigthed.cols();}
			else{maxDim=matALLMotifWeigthed.rows();}

            if (nbSupNmotifs>maxDim)
			{
                cerr<<"warning: the number of super n-motifs selected (-k) is greater than the maximum number of computed super n-motifs. -k is set to the maximum number of computed super n-motifs."<<endl;
                nbSupNmotifs=maxDim;
			}


			//compute SVD//
            Eigen::JacobiSVD<Eigen::MatrixXf> svd(matALLMotifWeigthed.matrix(), Eigen::ComputeThinU);
            //Eigen::BDCSVD<Eigen::MatrixXf> svd(matALLMotifWeigthed.matrix(), Eigen::ComputeThinU | Eigen::ComputeThinV);
            singularVal=svd.singularValues();

            //Brocken stick model

            if(nbSupNmotifs==0)
            {
                Eigen::RowVectorXf singularVal_precent=singularVal/singularVal.sum();
                Eigen::RowVectorXf brModel=singularVal;
                float tempbrModel;

                for(int i=0; i<brModel.size(); i++)
                {
                    tempbrModel=0;
                    for(int j=i; j<brModel.size(); j++)
                    {
                        tempbrModel+=1/float(j+1);
                    }
                    brModel(i)=tempbrModel/brModel.size();
                }

                int nbSupNmotifs2=0;
                while(singularVal_precent(nbSupNmotifs2)>brModel(nbSupNmotifs2))
                {nbSupNmotifs2++;}

                nbSupNmotifs=nbSupNmotifs2;

                if (nbSupNmotifs<2)
                {
                    nbSupNmotifs=2;
                }

            }

            matS_supernmotifs=svd.matrixU().leftCols(nbSupNmotifs);
            //matS_supernmotifs=randomizedSVD.matrixU().leftCols(nbSupNmotifs);//Resvd Test

            for(int i=0;i<nbSupNmotifs;i++)
			{matS_supernmotifs.col(i)=matS_supernmotifs.col(i)*(singularVal(i));}

            //Compute the SS dissimilarities using the cosine dissimilarity
            //if (p_outputOption==0)
            //{matDissimS2S=repSupermotifComputeMatrixDissimCosS2S(matS_supernmotifs);}

		}
        else if(p_outputOption==2)
        {

            int maxDim;
            if(matALLMotifWeigthed.rows()>matALLMotifWeigthed.cols())
            {maxDim=matALLMotifWeigthed.cols();}
            else{maxDim=matALLMotifWeigthed.rows();}

            if (nbSupNmotifs>maxDim)
            {
                cerr<<"warning: the number of super n-motifs selected (-k) is greater than the maximum number of computed super n-motifs. -k is set to the maximum number of computed super n-motifs."<<endl;
                nbSupNmotifs=maxDim;
            }

            //*******compute SVD*************************//
            Eigen::JacobiSVD<Eigen::MatrixXf> svd(matALLMotifWeigthed.matrix(), Eigen::ComputeThinU | Eigen::ComputeThinV);
            singularValFull=svd.singularValues();

            //Brocken stick model

            if(nbSupNmotifs==0)
            {
                Eigen::RowVectorXf singularVal_precent=singularValFull/singularValFull.sum();
                Eigen::RowVectorXf brModel=singularValFull;
                float tempbrModel;

                for(int i=0; i<brModel.size(); i++)
                {
                    tempbrModel=0;
                    for(int j=i; j<brModel.size(); j++)
                    {
                        tempbrModel+=1/float(j+1);
                    }
                    brModel(i)=tempbrModel/brModel.size();
                }

                int nbSupNmotifs2=0;
                while(singularVal_precent(nbSupNmotifs2)>brModel(nbSupNmotifs2))
                {nbSupNmotifs2++;}

                nbSupNmotifs=nbSupNmotifs2;

                if (nbSupNmotifs<2)
                {
                    nbSupNmotifs=2;
                }

            }

            singularVal=singularValFull.head(nbSupNmotifs);
            matS_supernmotifs=svd.matrixU().leftCols(nbSupNmotifs);
            matNM_supernmotifs=svd.matrixV().leftCols(nbSupNmotifs);

            for(int i=0;i<nbSupNmotifs;i++)
            {
             matS_supernmotifs.col(i)=matS_supernmotifs.col(i)*(singularVal(i));
             matNM_supernmotifs.col(i)=matNM_supernmotifs.col(i)*(singularVal(i));
            }

            //Compute the SS dissimilarities using the cosine dissimilarity
            //matDissimS2S=repSupermotifComputeMatrixDissimCosS2S(matS_supernmotifs);
            matDissimS2NM=repSupermotifComputeMatrixDissimCosS2NM(matS_supernmotifs,matNM_supernmotifs);

        }
        else if(p_outputOption==3)//Compute the secondary structure dissimilarities based on the n-motifs representation
        {
         cout<<"No super n-motifs computed (-p 3) ..."<<endl;
         //matDissimS2S=repSupermotifComputeMatrixDissimCosS2S(matALLMotifWeigthed);
        }
        else if ((p_outputOption==4))
        {
        cout<<"No super n-motifs computed (-p 4) ..."<<endl;
        }
        else if (p_outputOption==5)
		{
			int maxDim;
			if(matALLMotifWeigthed.rows()>matALLMotifWeigthed.cols())
			{maxDim=matALLMotifWeigthed.cols();}
			else{maxDim=matALLMotifWeigthed.rows();}

			//compute SVD
            if (nbSupNmotifs>maxDim)
			{
                cerr<<"warning: the number of super n-motifs selected (-k) is greater than the maximum number of computed super n-motifs. -k is set to the maximum number of computed super n-motifs."<<endl;
                nbSupNmotifs=maxDim;
			}

			//compute SVD//
            Eigen::JacobiSVD<Eigen::MatrixXf> svd(matALLMotifWeigthed.matrix(), Eigen::ComputeThinU | Eigen::ComputeThinV);
            singularValFull=svd.singularValues();
            //Brocken stick model
            if(nbSupNmotifs==0)
            {
                Eigen::RowVectorXf singularVal_precent=singularValFull/singularValFull.sum();
                Eigen::RowVectorXf brModel=singularValFull;
                float tempbrModel;

                for(int i=0; i<brModel.size(); i++)
                {
                    tempbrModel=0;
                    for(int j=i; j<brModel.size(); j++)
                    {
                        tempbrModel+=1/float(j+1);
                    }
                    brModel(i)=tempbrModel/brModel.size();
                }

                int nbSupNmotifs2=0;
                while(singularVal_precent(nbSupNmotifs2)>brModel(nbSupNmotifs2))
                {nbSupNmotifs2++;}

                nbSupNmotifs=nbSupNmotifs2;

                if (nbSupNmotifs<2)
                {
                    nbSupNmotifs=2;
                }

            }


            matS_supernmotifsFull=svd.matrixU();
            matNM_supernmotifsFull=svd.matrixV();

            singularVal=singularValFull.head(nbSupNmotifs);
            matS_supernmotifs=matS_supernmotifsFull.leftCols(nbSupNmotifs);
            matNM_supernmotifs=matNM_supernmotifsFull.leftCols(nbSupNmotifs);;


            //Compute super n-motifs representation of n-motifs

            for(int i=0;i<nbSupNmotifs;i++)
			{
				matS_supernmotifs.col(i)=matS_supernmotifs.col(i)*(singularVal(i));
                matNM_supernmotifs.col(i)=matNM_supernmotifs.col(i)*(singularVal(i));
			}

            //Compute the dissimilarities between SS and n-motifs in the super n-motif space using the cosine dissimilarity
            matDissimS2NM=repSupermotifComputeMatrixDissimCosS2NM(matS_supernmotifs,matNM_supernmotifs);
            //Compute the SS dissimilarities using the cosine dissimilarity
            //matDissimS2S=repSupermotifComputeMatrixDissimCosS2S(matS_supernmotifs);
		}


}