Output of DFT is the same as input

asked 2017-06-30 12:22:36 -0500

I have a problem with understanding DFT.

I'm trying to create simple program to test this function.

vector <complex<double> > singlePointAsComplex;
std::complex<double> c(1,2);
singlePointAsComplex.push_back (c);
Mat resMat;
dft(singlePointAsComplex, resMat, DFT_SCALE);
std::cout << "resMat = " << std::endl << resMat << std::endl;

As the output i receive:

resMat = [1, 2]

What i'm doing wrong?

edit retag flag offensive close merge delete

Comments

the DFT of a single number is just DC, itself (so, the result is correct !).

to see anything in * frequency domain*, you need more complex input(pun, harrr), like more dimensions

berak gravatar imageberak ( 2017-06-30 12:29:11 -0500 )edit

I'm working with OP to solve this problem, we're both new to image analysis and the documentation is quite complicated. How should the dft() function be called if we want to calculate DFT for a single point of the image contour? I was expecting that converting both coordinates into a single complex number should be enough to pass it into dft() and get a fourier descriptor - a single value in output matrix. But probably my way of thinking is incorrect.

camilloz gravatar imagecamilloz ( 2017-06-30 12:59:51 -0500 )edit

calculate DFT for a single point of the image contour? -- that sounds like a good point to "hook into your problem"

again, "a single point" does not make much sense here. do you intend to do some "frequency based filtering" on your contour ? (again, you'd have to pass the whole thing, not a single point)

care to explain more ?

berak gravatar imageberak ( 2017-06-30 13:07:56 -0500 )edit
1

Ok, so what we are trying to accomplish is:

  1. Detect the object contour from the image,
  2. Take some number of points returned by Canny. We don't want all of them,
  3. Calculate DFT values of the contour points from #2,
  4. Normalize the values - they will be 'features' of our objects (we have a few images of two classes that have slightly different contours),
  5. Perform some classifications using alghoritms like kNN, NM etc. on features from #4

And since we're stuck in point #3 and have no idea how to use dft() we decided to play with the function on the smallest possible data - a single point. However we're disappointed with the results returned.

camilloz gravatar imagecamilloz ( 2017-06-30 14:00:37 -0500 )edit

2: "contour points" that's more than one

also, fft/dct/dtf -- it's all about mapping a continuous time spectrum to frequency domain.

for the discrete version, -- you have to make an array from 0 to tmax(or xmax, in your case), insert the values you have at known x positions, and fill the rest with zeros, again, it needs to be "continuous".

berak gravatar imageberak ( 2017-06-30 14:02:58 -0500 )edit

can it be, you're trying to match shapes using fourier descriptors ?

berak gravatar imageberak ( 2017-06-30 14:12:19 -0500 )edit

yes we are

camilloz gravatar imagecamilloz ( 2017-06-30 14:14:42 -0500 )edit
1

if it's really fourier descriptors, have a look here

@LBerger, i'd be happy, if you would be taking over this one ;)

berak gravatar imageberak ( 2017-06-30 14:19:15 -0500 )edit

My PR is not ready today but you can first try to use this post

LBerger gravatar imageLBerger ( 2017-06-30 14:30:55 -0500 )edit

I think that we're trying to do something simple but without proper preparation we're unable to do anything.

Like my friend described we have an image. It's a image of object. We detect contour and put it in vector <point> ( vector with 2541 elements for example [20 , 70]. After using dft() and normalize. As output we know that we need 64 elements. It's tricky because we don't exactly know what our output is. We only know how is should look like. We don't have much information about image analysis and I think that's our biggest problem.

I believe that we should us two examples from openCV documentation: http://docs.opencv.org/2.4/doc/tutori...

doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.html

ShadowUS gravatar imageShadowUS ( 2017-06-30 14:57:12 -0500 )edit