Exemple #1
0
Mat CmSaliencyRC::GetSR(CMat &img3f)
{
	Size sz(64, 64);
	Mat img1f[2], sr1f, cmplxSrc2f, cmplxDst2f;
	cvtColor(img3f, img1f[1], CV_BGR2GRAY);
	resize(img1f[1], img1f[0], sz, 0, 0, CV_INTER_AREA); 

	img1f[1] = Mat::zeros(sz, CV_32F);
	merge(img1f, 2, cmplxSrc2f);
	dft(cmplxSrc2f, cmplxDst2f);
	AbsAngle(cmplxDst2f, img1f[0], img1f[1]);

	log(img1f[0], img1f[0]);
	blur(img1f[0], sr1f, Size(3, 3));
	sr1f = img1f[0] - sr1f;

	exp(sr1f, sr1f);
	GetCmplx(sr1f, img1f[1], cmplxDst2f);
	dft(cmplxDst2f, cmplxSrc2f, DFT_INVERSE | DFT_SCALE);
	split(cmplxSrc2f, img1f);

	pow(img1f[0], 2, img1f[0]);
	pow(img1f[1], 2, img1f[1]);
	img1f[0] += img1f[1];

	GaussianBlur(img1f[0], img1f[0], Size(3, 3), 0);
	normalize(img1f[0], img1f[0], 0, 1, NORM_MINMAX);
	resize(img1f[0], img1f[1], img3f.size(), 0, 0, INTER_CUBIC);

	return img1f[1];
}
Exemple #2
0
/*
degraded :  degraded input image
filter   :  filter which caused degradation
snr      :  signal to noise ratio of the input image
return   :   restorated output image
*/
Mat Dip4::wienerFilter(Mat& degraded, Mat& filter, double snr){

  // be sure not to touch them
  degraded = degraded.clone();
  filter = filter.clone();
   
  // Q_k = conjugate_transpose(P_k) / | P_k | ^2  + 1/SNR^2

  Mat filterFreq = Mat(filter.size(), CV_32F);
  
  
  Mat planesFilter[] = {filterFreq, Mat::zeros(filterFreq.size(), CV_32F)};
  
  merge(planesFilter, 2, filterFreq);
  
  dft(filterFreq, filterFreq, DFT_COMPLEX_OUTPUT); // filterFreq == P


  // create Q

  split(filterFreq, planesFilter);

  Mat Re = planesFilter[0];
  Mat Im = planesFilter[1];

  Mat QRe = Re.clone();
  Mat QIm = Im.clone();

  for (int x = 0; x < filterFreq.rows; x++) for (int y = 0; y < filterFreq.cols; y++) {

    // A*_ij = Ã_ji
    float reConjugateTranspose = Re.at<float>(y, x);
    float imConjugateTranspose = -Im.at<float>(y, x);

    float resq = Re.at<float>(x, y) * Re.at<float>(x, y);
    float imsq = Im.at<float>(x, y) * Im.at<float>(x, y);
    float absreim = sqrt(resq + imsq);

    QRe.at<float>(x, y) = reConjugateTranspose / (absreim * absreim + 1/(snr * snr));
    QIm.at<float>(x, y) = imConjugateTranspose / (absreim * absreim + 1/(snr * snr));

  }
  
  Mat Q = Mat::zeros(filterFreq.size(), CV_32F);

  Mat qplanes[] = {QRe, QIm};
  
  merge(qplanes, 2, Q);

  Mat original;

  dft(Q, Q, DFT_INVERSE + DFT_SCALE);
  split(Q, planes);
  filter2D(degraded, original, -1, planes[0]);
  normalize(original, original, 0, 255, CV_MINMAX);
  original.convertTo(original, CV_8UC1);

  return original;

}
Exemple #3
0
int main()
{
	int N;
	std::scanf("%d", &N);
	read_number(N, num_a);
	read_number(N, num_b);

	int p = 1;
	while(p < N) p <<= 1;
	N = p << 1;
	init_epsilon(N);
	dft(N, num_a, 0, 1, epsilon);
	dft(N, num_b, 0, 1, epsilon);
	for(int i = 0; i != N; ++i)
		num_a[i] *= num_b[i];

	dft(N, num_a, 0, 1, arti_epsilon);
	for(int i = 0; i != N; ++i)
		ans[i] = int(num_a[i].real() / N + 1.0e-9);
	for(int i = 0; i <= N; ++i)
	{
		ans[i + 1] += ans[i] / 10;
		ans[i] %= 10;
	}

	int len = N + 1;
	while(!ans[len] && len) --len;
	for(int i = len; i >= 0; --i)
		std::printf("%c", char(ans[i] + '0'));

	return 0;
}
Exemple #4
0
void check_blink(){
         max_input=0;
         BB_flag=0;
         X=dft();
         if(X>FThreshold){
        	 if(ON /*&& max_input>110*/){
        		 big_blink=1;
        	 }
        	 else if(max_input>120){//see the max adc val corresssponding to saturation output of eog ckt
            	 for(i=0;i<4;i++){
            		 X=dft();
            		 if(max_input>100 || max_slope>30){
            			 BB_flag++;
            		 }

            	 }
                 if(BB_flag>0){
                		 big_blink=1;
                 }
            	 else
            	     small_blink=1;
        	 }
		     //if(X>400)  big_blink=1;//big blink fourier value;same values for small and big blink
		     //if(counter_BigB>7) big_blink=1;//arbitrary counter
		     else
                 small_blink=1;
        }
}
Exemple #5
0
 void run(int)
 {
     RNG& rng = theRNG();
     for( int i = 0; i < 10; i++ )
     {
         int m = rng.uniform(2, 11);
         int n = rng.uniform(2, 11);
         int depth = rng.uniform(0, 2) + CV_32F;
         Mat src8u(m, n, depth), src(m, n, depth), dst(m, n, CV_MAKETYPE(depth, 2));
         Mat z = Mat::zeros(m, n, depth), dstz;
         randu(src8u, Scalar::all(0), Scalar::all(10));
         src8u.convertTo(src, src.type());
         dst = Scalar::all(123);
         Mat mv[] = {src, z}, srcz;
         merge(mv, 2, srcz);
         dft(srcz, dstz);
         dft(src, dst, DFT_COMPLEX_OUTPUT);
         if (cvtest::norm(dst, dstz, NORM_INF) > 1e-3)
         {
             cout << "actual:\n" << dst << endl << endl;
             cout << "reference:\n" << dstz << endl << endl;
             CV_Error(CV_StsError, "");
         }
     }
 }
/************ Learn Spatio-Temporal Context Model ***********/
void STCTracker::learnSTCModel(const Mat image)
{
	// step 1: Get context prior and posterior probability
	getCxtPriorPosteriorModel(image);
	
	// step 2-1: Execute 2D DFT for prior probability
	Mat priorFourier;
	Mat planes1[] = {cxtPriorPro, Mat::zeros(cxtPriorPro.size(), CV_64F)};
    merge(planes1, 2, priorFourier);
	dft(priorFourier, priorFourier);

	// step 2-2: Execute 2D DFT for posterior probability
	Mat postFourier;
	Mat planes2[] = {cxtPosteriorPro, Mat::zeros(cxtPosteriorPro.size(), CV_64F)};
    merge(planes2, 2, postFourier);
	dft(postFourier, postFourier);

	// step 3: Calculate the division
	Mat conditionalFourier;
	complexOperation(postFourier, priorFourier, conditionalFourier, 1);

	// step 4: Execute 2D inverse DFT for conditional probability and we obtain STCModel
	dft(conditionalFourier, STModel, DFT_INVERSE | DFT_REAL_OUTPUT | DFT_SCALE);

	// step 5: Use the learned spatial context model to update spatio-temporal context model
	addWeighted(STCModel, 1.0 - rho, STModel, rho, 0.0, STCModel);
}
Exemple #7
0
/*
Performes a convolution by multiplication in frequency domain
in		input image
kernel		filter kernel
return		output image
*/
Mat frequencyConvolution(Mat& in, Mat& kernel) {

	const int kw = kernel.cols;
	const int kh = kernel.rows;

	Mat kernelBig = Mat::zeros(in.size(), in.type());
	for (int x = 0; x < kw; ++x) {
		for (int y = 0; y < kh; ++y) {
			kernelBig.at<float>(x, y) = kernel.at<float>(x, y);
		}
	}
	Mat kernelBigShifted = circShift(kernelBig, -(kw/2), -(kh/2));

	// transform into frequency domain
	Mat freqIn = Mat(in.size(), CV_32FC2); // complex
	Mat freqKernel = Mat(kernelBigShifted.size(), CV_32FC2); // complex
	dft(in, freqIn);
	dft(kernelBigShifted, freqKernel);

	// multiply in frequency domain (-> convolute in spatial domain)
	Mat freqRes = Mat(kernelBig.size(), CV_32FC2); // complex
	mulSpectrums(freqIn, freqKernel, freqRes, 0);

	// transform back into spatial domain
	Mat res(in.size(), in.type());
	dft(freqRes, res, DFT_INVERSE | DFT_SCALE);

	return res;
}
Exemple #8
0
int main()
{
    scanf("%d",&C);scanf("%c",&ch);a.clear();b.clear();
    for (int i=1;i<=C;i++){a.p_b(0);b.p_b(0);}
    for (int i=1;i<=C;i++){scanf("%c",&ch);a[C-i]=ch-48;}scanf("%c",&ch);
    for (int i=1;i<=C;i++){scanf("%c",&ch);b[C-i]=ch-48;}
    L=0,N=1;while ((N>>1)<C) N*=2,++L;
    while (a.size()<N) a.p_b(0);while (b.size()<N) b.p_b(0);
    /*core*/a=dft(a);b=dft(b);for (int i=0;i<N;i++) a[i]=(LL)a[i]*b[i]%bigp;a=idft(a);
    for (int i=0;i<N;i++){a[i+1]=(a[i+1]+a[i]/10);a[i]%=10;}
    len=N-1;while ((len>1)&&(a[len]==0)) --len;
    for (int i=len;i>=0;i--) printf("%d",a[i]);printf("\n");
}
Exemple #9
0
    virtual int filter(const Mat &src, Mat &dest) const
    {
        Mat h; src.convertTo(h, CV_32F);
        Mat h2(h.size(), h.type());

        dft(h, h2, DFT_ROWS); // dft instead of dct solves pow2 issue

        Mat h3 = (keep>0) ?
                 h2(Rect(0, 0, std::min(keep, h2.cols-1), 1)) :
                 h2;

        dft(h3, dest, DCT_INVERSE | DFT_SCALE | DFT_ROWS);
        return 0;
    }
Exemple #10
0
int main(int argc, char *argv[])
{
    if(argc < 3) die("Insufficient arguments supplied.");
    int length = atoll(argv[1]);
    float prec = atof(argv[2]);

    printf("sizeof(length) = %lu\n", sizeof(length));

    float *samples = gensample(length, prec, hamming);
    float *K = malloc(length*sizeof(float));
    memset(K, 0, length);
    float *X_real = malloc(length*sizeof(float));
    memset(X_real, 0, length);
    float *X_img = malloc(length*sizeof(float));
    memset(X_img, 0, length);

    float *result = dft(samples, length, X_real, X_img, K);
    log_data(length, result, K);

    free(X_real);
    free(X_img);
    free(K);
    free(samples);
    return 0;
}
Exemple #11
0
Fichier : dft.c Projet : wicker/dft
int dft_test(int len,FILE* outfile) {

  printf("---------------------------------------\n");
  printf("              dft test              \n");
  printf("---------------------------------------\n");

  double complex a[20] = {0.0+0.0I};
  double complex b[20] = {0.0+0.0I};
  double complex *pa = a, *pb = b;

  for (int i = 0; i < len; i++) {
    a[i] = 1.00;
    dft(pa,pb,len);
    fprintf(outfile, "\"case %d\"\n",i);
    print_dft_case(len,pa,pb,outfile);
//  fprintf(outfile,"\"case %d input\"\n",i);
//  printf("input array #%d\n",i);
//  print_complex_array(len,pa,outfile,"in");
//  fprintf(outfile,"\"case %d output\"\n",i);
//  printf("output array #%d\n",i);
//  print_complex_array(len,pb,outfile,"out");
    a[i] = 0.00;
  }

  return 0;
}
void dft(struct graph *g, struct vnode *v, int id)
{
  struct enode *e;
  int first;
 
  first = 1;
  v->visited = 1;
  e = v->edge;
  while(e != NULL)
  {
    if( !g->vn[e->vndx].visited)
    {
      if(first)
      {
        first = 0;
      }else{
        indent(id);
      }
    
      printf("-->%d", g->vn[e->vndx].item);
      id += 3 + INCR(g->vn[e->vndx].item);
      dft(g,&(g->vn[e->vndx]),id);
      id -= 3 + INCR(g->vn[e->vndx].item);
    }
    e = e->next;
  }
  if(first)
    printf("\n");
}
Exemple #13
0
void fft2(Mat_<float> src)
{
	int x = getOptimalDFTSize(2* src.rows );
	int y = getOptimalDFTSize(2* src.cols );
	copyMakeBorder(src, src, 0, (x - src.rows), 0, (y - src.cols), BORDER_CONSTANT, Scalar::all(0));
	     // Get padded image size
	     const int wx = src.cols, wy = src.rows;
	     const int cx = wx/2, cy = wy/2;

	//--------------------------------//
	// DFT - performing		     //
	cv::Mat_<float> imgs[] = {src.clone(), Mat::zeros(src.size(), CV_32F)};
	cv::Mat_<cv::Vec2f> img_dft;
	merge(imgs,2,img_dft);
	dft(img_dft, img_dft);
	split(img_dft,imgs);
	cv::Mat_<float> magnitude, phase;
	cartToPolar(imgs[0],imgs[1],magnitude,phase);
	dftshift(magnitude);
	magnitude = magnitude + 1.0f;
	log(magnitude,magnitude);
	normalize(magnitude,magnitude,0,1,CV_MINMAX);
	namedWindow("img_dft",WINDOW_NORMAL);
	imshow("img_dft",magnitude);
	waitKey(0);
	cout << "out" << endl;
}
bool ImageLocationRenderer::RenderPathAndFilename(std::ostream &reply, Context &c,
		const ROAnything &config)
{
	ROAnything name;
	if (!config.LookupPath(name, "ImageName")) {
		if (config.GetType() == AnyArrayType) {
			name = config[0L];
		}
	}

	if (!name.IsNull()) {
		ROAnything path;
		Anything dft("/");

		if (!config.LookupPath(path, "ImagePath")) {
			path = c.Lookup("ImagePath");
			if (path.IsNull()) {
				path = dft;
			}
		}
		Render(reply, c, path);
		Render(reply, c, name);

		return true;
	}
	return false;
}
Exemple #15
0
std::vector<double> fft(std::vector<double> signal)
{
    float N = signal.size();
    std::vector<std::complex<double>> dft(N);
    int32_t range = N/2;
    //range = 40;
    //int32_t range = 19;
    std::complex<double> j (0.0,1.0);

    for(int32_t k = -range; k<= range; k++)
    {
        for(uint32_t inc = 0; inc < N; inc++)
        {
            std::complex<double> tmp (k * (inc + 1) * 2 * PI / N, 0);
            std::complex<double> tmp2 (1.0/N * signal[inc], 0);
            dft[k + range] = dft[k + range] + tmp2 * pow(E_,-j * tmp);
        }
    }

    std::vector<double> final_result(N);
    for(uint32_t i = 0; i< N; ++i )
    {
        final_result[i] = abs(dft[i]);
    }
    return final_result;
}
void TransformDecoding(float pDataMatrix[N_TRANS_DECODER_IN_MAX], float pDecSeq[N_TRANS_DECODER_OUT_MAX], int NumLayer, int MDFT)
{
#define NUM_UL_SYMB_SF 14
#define NUM_LAYER 2
#define NUM_MDFT 75
//	int NumLayer = lte_phy_params->N_rx_ant;
//	int MDFT = lte_phy_params->N_dft_sz;
#pragma HLS ARRAY_PARTITION variable=pDecSeq cyclic factor=2 dim=1
	int NumULSymbSF = LTE_PHY_N_SYMB_PER_SUBFR;
	for(int nlayer=0;nlayer</*NumLayer*/NUM_LAYER;nlayer++)
	{
		for(int nsym=0;nsym</*NumULSymbSF*/NUM_UL_SYMB_SF-2;nsym++)
		{
#pragma HLS LOOP_FLATTEN
			int idx = nlayer*(MDFT*(NumULSymbSF-2))+nsym*MDFT;
			float norm = (float)sqrt((float)MDFT);
			dft(MDFT, pDataMatrix + idx * 2, pDecSeq + idx * 2, -1);
			for(int m = 0; m < /*MDFT*/ NUM_MDFT; m++)
			{
#pragma HLS PIPELINE II=4
#pragma HLS DEPENDENCE array inter false
				pDecSeq[2 * (idx + m) + 0] = pDecSeq[2 * (idx + m) + 0] / norm;
				pDecSeq[2 * (idx + m) + 1] = pDecSeq[2 * (idx + m) + 1] / norm;
			}                              
		}
	}
}
Exemple #17
0
static double verify_impulse(fftd_func *dft,
			    int n, int veclen,
			   COMPLEX *inA,
			   COMPLEX *inB,
			   COMPLEX *inC,
			   COMPLEX *outA,
			   COMPLEX *outB,
			   COMPLEX *outC,
			   COMPLEX *tmp,
			   int rounds)
{
     int N = n * veclen;
     COMPLEX impulse;
     int i;
     double e, maxerr = 0.0;

     /* test 2: check that the unit impulse is transformed properly */
     RE(impulse) = 1.0;
     IM(impulse) = 0.0;
     
     for (i = 0; i < N; ++i) {
	  /* impulse */
	  RE(inA[i]) = 0.0;
	  IM(inA[i]) = 0.0;
	  
	  /* transform of the impulse */
	  outA[i] = impulse;
     }
     for (i = 0; i < veclen; ++i)
	  inA[i * n] = impulse;

     /* a simple test first, to help with debugging: */
     dft((double *)outB, (double *)inA);
     e = acmp(outB, outA, N);
     if(e > maxerr) maxerr = e;

     for (i = 0; i < rounds; ++i) {
	  fill_random(inB, N);
	  asub(inC, inA, inB, N);
   	  dft((double *)outB, (double *)inB);
   	  dft((double *)outC, (double *)inC);
	  aadd(tmp, outB, outC, N);
	  e = acmp(tmp, outA, N);
	  if(e > maxerr) maxerr = e;
     }
     return maxerr;
}
Exemple #18
0
 int mul(int n1, int *x1, int n2, int *x2) {
     n = std::max(n1, n2);
     for (bn = 0; (1<<bn) < n; ++bn); ++bn;
     n = 1 << bn;
     for (int i=0; i<n; ++i) a[i] = b[i] = comp(0, 0);
     for (int i=0; i<n1; ++i) a[i] = comp(x1[i], 0);
     for (int i=0; i<n2; ++i) b[i] = comp(x2[i], 0);
     dft(a, false); dft(b, false);
     for (int i=0; i<n; ++i) {
         tmp[i].x = a[i].x * b[i].x - a[i].y * b[i].y;
         tmp[i].y = a[i].x * b[i].y + a[i].y * b[i].x;
     }
     dft(tmp, true);
     for (int i=0; i<n; ++i) res[i] = (type)(tmp[i].x/n + 0.1);
     for (--n; n && !res[n]; --n);
     return n+1;
 }
void Feature::calcFrequency()
{
    // TODO: optimize this part
    
    if (mAreaVec.size() < MAX_AREA_VEC_SIZE) {
        frequency = -1;
        return;
    }
    
    // limit n to integer power of 2 for simplicity
    // in fact, you can use function 'getOptimalDFTSize' to pad the input array
    assert((MAX_AREA_VEC_SIZE & (MAX_AREA_VEC_SIZE - 1)) == 0);
   
    /*domon:::::debug
	vector<double>::size_type size = mAreaVec.size();
    
    for (int i = 0; i < size - 1; i++) {
        mAreaVec[i] = 600;
    }
    for (int i = size - 1; i < size; i++) {
        mAreaVec[i] = 600 + 10;
    }*/
 
    vector<double> spec(MAX_AREA_VEC_SIZE);
    dft(mAreaVec, spec);
    /*domon:::::debug   
 
    printAreaVec();
    vector<double>::size_type dft_size = spec.size();
    
    for (int i = 0; i < dft_size; i++) {
        cout << spec[i];
        if (i != dft_size - 1) {
            cout << "; ";
        } else {
            cout << endl;
        }
    }

    //domon:::::debug*/
    double maxAmpl = 0;
    int idx = 0;
    for (int i = 1; i < MAX_AREA_VEC_SIZE; i += 2) {
        double ampl = (i == MAX_AREA_VEC_SIZE - 1) ? spec[i] :
            sqrt(spec[i] * spec[i] + spec[i + 1] * spec[i + 1]);
        if (ampl > maxAmpl) {
            maxAmpl = ampl;
            idx = (i + 1) / 2;
        }
    }
 /*   
    double fps = videoHandler->getVideoFPS();
    frequency = fps / MAX_AREA_VEC_SIZE * maxAmpl;  //idx;
*/
#ifdef DEBUG_OUTPUT
    cout << "fps: " << fps << ", frequency: " << frequency << endl;
#endif
}
Exemple #20
0
/*
in       input image
kernel   filter kernel
return   output image
*/
Mat Dip3::frequencyConvolution(Mat& in, Mat& kernel){

   Mat tempA = Mat::zeros(in.rows, in.cols, CV_32FC1);
   Mat tempB = Mat::zeros(in.rows, in.cols, CV_32FC1);
   
   for (int x = 0; x < kernel.rows; x++) for (int y = 0; y < kernel.cols; y++) {
      tempB.at<float>(x, y) = kernel.at<float>(x, y);
   }
   
   tempB = circShift(tempB, -1, -1);

   dft(in, tempA, 0);
   dft(tempB, tempB, 0);
   mulSpectrums(tempA, tempB, tempB, 0);
   dft(tempB, tempA, DFT_INVERSE + DFT_SCALE);

   return tempA;
}
// Fourier descriptor
int test_fourier_descriptor(vector_t *fd, point_list_t *plist)
{
  int i, n;
  vector_t *time, *fourier, *fd;
  complex_t comp;

  assert(fd);
  assert(plist);
  assert(vecter_get_length(fd) == point_list_get_count(plist));

  time = cvector_new_and_copy_point_list(plist);
  fourier = vector_new(vector_get_length(time), true);
  //fd = vector_new(vector_get_length(time), true);

  dft(fourier, time);
  n = vector_get_length(time);

  // filtering
  /*
  comp.real = comp.imag = 0.0;
  for (i = n / 2 - 16; i < n / 2 + 16; i++) {
    cvector_put_value(comp, i, fourier);
  }
  */

  ///////////////////////  Normalization ////////////////////////////
  vector_copy(fd, fourier);
  // For translation invariance, 0 frequency must have a zero value
  cvector_put_value(comp, 0, fd);

  // For scale invariance,
  // fourier descriptor must be divied by the absolute of 1 frequency component.
  cvector_read_value(&comp, 1, fd);
  val = complex_get_abs(&comp);
  vector_divide_scalar(fd, val);
  ivector_divide_scalar(fd, val);

  // For rotating and changes in starting point
  // remove all phase information and
  // consider only absolute values of the descriptor element
  //f = fopen("fourier_descriptor.txt", "a+");
  //fprintf(f, "%s", fn);
  for (i = 0; i < vector_get_length(fd); i++) {
    cvector_read_value(&comp, i, fd);
    val = complex_get_abs(&comp);
    vector_put_value(val, i, fd);
    ivector_put_value(0, i, fd);
    //fprintf(f, ", %lf", val);
  }
  //fprintf(f, "\n");
  //fclose(f);
  ///////////////////////////////////////////////////////////////////

  //  idft(time, fourier);
  return n;
}
Exemple #22
0
int fourier(double *jr, double *ji, int n, int iflag)
{
    int i2;
    
    if ((i2 = ilog2(n)) > 0) {
	return fft(jr, ji, n, i2, iflag);
    } else {
	return dft(jr, ji, n, iflag);
    }
}
Exemple #23
0
	/*fft算法,输入图像为8U(灰度图),输出为2*32F的图像(实部与虚部,未进行四角校正)*/
	Mat mydft(Mat &src)
	{
		Mat src2;
		src.convertTo(src2, CV_32F);
		Mat planes[] = { Mat_<float>(src2), Mat::zeros(src2.size(), CV_32F) };
		Mat complexI;
		merge(planes, 2, complexI);
		dft(complexI, complexI);
		return complexI;
	}
Exemple #24
0
void DenseGaussKernel(float sigma, const Mat &x,const Mat &y, Mat &k){
  Mat xf, yf;
  dft(x, xf, DFT_COMPLEX_OUTPUT);
  dft(y, yf, DFT_COMPLEX_OUTPUT);
	double xx = norm(x);
	xx = xx*xx;
	double yy = norm(y);
	yy = yy*yy;

  Mat xyf;
  mulSpectrums(xf, yf, xyf, 0, true);

	Mat xy;
	cv::idft(xyf, xy, cv::DFT_SCALE | cv::DFT_REAL_OUTPUT); // Applying IDFT
  CircShift(xy, scale_size(x.size(),0.5));
	double numelx1 = x.cols*x.rows;
	//exp((-1 / (sigma*sigma)) * abs((xx + yy - 2 * xy) / numelx1), k); //thsi setting is fixed by version 2(KCF)
  exp((-1 / (sigma*sigma)) * max(0,(xx + yy - 2 * xy) / numelx1), k);
}
Exemple #25
0
Cmat *power_spectrum_apply(PowerSpectrum *self, Cmat *data) {
  Cmat *ps = cmat_new(data->rows, self->n_uniq_fft_points);
  int i,j;
  for (i=0;i<data->rows;++i) {
      Cmat * ffts = dft(data->data[i], data->cols, self->nfft);
      for (j=0;j<self->n_uniq_fft_points;++j) {
          ps->data[i][j] = pow(ffts->data[0][j],2) + pow(ffts->data[1][j],2);
      }
      cmat_free(ffts);
  } 
  return ps;
}
Exemple #26
0
	/*fft-inv算法,输入图像为有实部和虚部的2*32F图像,输出为8U灰度图*/
	Mat myinvdft(Mat &src)
	{
		dft(src, src, DFT_INVERSE);
		Mat dst;
		vector<Mat_<float>> planes;
		split(src, planes);
		magnitude(planes[0], planes[1], planes[0]);
		src = planes[0];
		normalize(src, src, 0, 255, CV_MINMAX);
		src.convertTo(dst, CV_8U);
		return dst;
	}
Exemple #27
0
void check_blink(){
         max_input=0;
         X=dft();
         if(X>FThreshold){
             if(max_input>86)  big_blink=1; //see the max adc val corresssponding to saturation output of eog ckt
		     //if(X>400)  big_blink=1;//big blink fourier value;same values for small and big blink
		     //if(counter_BigB>7) big_blink=1;//arbitrary counter
		     else
                 small_blink=1;
         }

}
Exemple #28
0
void fft(std::vector<int> a, std::vector<int> b, std::vector<int>& c) {
	c.clear();
	int t = a.size() + b.size();
	int n = 1; while (n < t) n *= 2;
	int *ta = new int[n], *tb = new int[n];
	for (int i = 0; i < n; i++) {
		ta[i] = (i >= a.size() ? 0 : a[i]);
		tb[i] = (i >= b.size() ? 0 : b[i]);
	}
	dft(ta, n, 1), dft(tb, n, 1);
	for (int i = 0; i < n; i++)
		ta[i] = 1LL * ta[i] * tb[i] % P;
	dft(ta, n, -1);
	int rev = pwr(n, P-2, P);
	for (int i = 0; i < n; i++) ta[i] = 1LL * ta[i] * rev % P;
	c.resize(a.size()+b.size()-1);
	for (int i = 0; i < a.size()+b.size()-1; i++)
		c[i] = ta[i];
	delete [] ta;
	delete [] tb;
}
Exemple #29
0
void dft(int n, std::complex<double>* buffer,
	int offset, int step, std::complex<double>* epsilon)
{
	if(n == 1) return;
	int m = n >> 1;
	dft(m, buffer, offset, step << 1, epsilon);
	dft(m, buffer, offset + step, step << 1, epsilon);
	for(int k = 0; k != m; ++k)
	{
		int pos = 2 * step * k;
		temp[k] = buffer[pos + offset] 
			+ epsilon[k * step] 
			* buffer[pos + offset + step];

		temp[k + m] = buffer[pos + offset] 
			- epsilon[k * step] 
			* buffer[pos + offset + step];
	}

	for(int i = 0; i != n; ++i)
		buffer[i * step + offset] = temp[i];
}
Exemple #30
0
int main()
{
	V = fio, E = fio;
	while (E--)
		if ((u = fio) != (v = fio))
			edg_ins(EA, u, v);
	for (u = 1; u <= V; ++u)
		f[u] = 1;
	for (u = 1; u <= V; ++u)
		if (!dfn[u]) dft(u);
	printf(lld "\n", ans);
	return 0;
}