I have a 3D array of real data that I'd like to transform with a either a DST or DCT along one axis and normal DFT's along the other two axes. The result should be a 3D complex array that holds this transformation's coefficients.
Do you know if the FFTW3 package offers such a routine - possibly in parallel - out of the box? FFTW3 provides such a routine for a simple 3D DFT in all three directions.
And if not, would you might have a hint on how to achieve it the best way in C/C++?
My naive idea: Assembly of DST/DCT followed by a 2D real-to-complex transformation along the first axis inside some wrapping routine. Then, one could think of a 1D decomposition to achieve the parallelism. A 2D would be nicer but much more work.
PS:
This transformation is used in a spectral method for solving the Navier-Stokes equation.
Your naive idea is the way to go. Individual dimensions can be transformed independently.
Related
For a little background, I'm doing a whole lot of image filtering, using a bunch of complex-valued filters.
I generate the real and imaginary parts of the filters separately (its more efficient that way), and store them in two separate arrays.
I followed this guide on how to do dft's in opencv.
Basically, I have to
loop through my filters
call merge to combine the real and imaginary parts
perform a DFT
call split to separate real and imaginary again
compute the magnitude of the response
I do this, and its fairly slow. I initially thought I needed a faster FFT library, but based on Visual Studio's profiler, it turns out that cv::split() and cv::merge() take an order of magnitude more time than the actual DFT does. In fact, most of the running-time is spent in these two functions.
The whole split/merge thing seems a little redundant to me, and the fact that they're the most time consuming functions is pretty annoying. Is there a faster way to do what I'm trying to do?
OpenCV matrices are stored in interleaved format. That means for a two channel image with channels A and B, a 4x1 matrix would be stored in the order ABABABAB. If you have two different planes, you have AAAA and BBBB.
It is probably hardest to convince the DFT to operate on non-interleaved input. However maybe you are able to store your filters as a two-channel matrix in the first place?
To compute the magnitude from the two channels, you can loop through all elements and call cv::norm on them or do the calculation yourself. You can speed that up further by using SSE and/or TBB.
So at least you save one of the conversions.
I've been messing around with OpenGL a little bit and I don't fully understand what the purpose of the matrices are for. Is it to provide animation for the objects or something?
Matrices are used to represent transformations of points and vectors in openGL. I suggest you brush up on some linear algebra, and, in particular, you learn about transformation matrices. You cannot be a good graphics programmer without understanding transformations!
For 3D vectors, 4x4 matrix stores nicely all the needed transforms (move, rotate, scale, and project) in one simple package. And not only that, you can cascade transformations together by simple multiply operation. I think that is the main reason for those. Of course, you can also have 3x3 rotation matrices, as well as quaternions involved in transforms: still, 4x4 matrix can store all those transforms, although extracting single operations out of that can be pretty tricky.
I'm trying to do pose estimation (actually [Edit: 3DOF] rotation is all I need) from a planar marker with 4 corners = 4 coplanar points.
Up until today I was under the impression from everything I read that you will always compute a homography (e.g. using DLT) and decompose that matrix using the various methods available (Faugeras, Zhang, the analytic method which is also described in this post here on stackexchange) and refine it using non-linear optimization, if necessary.
First minor question: if this is an analytical method (simply taking two columns from a matrix and creating an orthonormal matrix out of these resulting in the desired rotation matrix), what is there to optimize? I've tried it in Matlab and the result jitters badly so I can clearly see the result is not perfect or even sufficient, but I also don't understand why one would want to use the rather expensive and complex SVDs used by Faugeras and Zhang if this simple method yields results already.
Then there are iterative pose estimation methods like the Ortohogonal Iteration (OI) Algorithm by Lu et al. or the Robust Pose Estimation Algorithm by Schweighofer and Pinz where there's not even a mention of the word 'homography'. All they need is an initial pose estimation which is then optimized (the reference implementation in Matlab done by Schweighofer uses the OI algorithm, for example, which itself uses some method based on SVD).
My problem is: everything I read so far was '4 points? Homography, homography, homography. Decomposition? Well, tricky, in general not unique, several methods.' Now this iterative world opens up and I just cannot connect these two worlds in my head, I don't fully understand their relation. I cannot even articulate properly what my problem is, I just hope someone understands where I am.
I'd be very thankful for a hint or two.
Edit: Is it correct to say: 4 points on a plane and their image are related by a homography, i.e. 8 parameters. Finding the parameters of the marker's pose can be done by calculating and decomposing the homography matrix using Faugeras, Zhang or a direct solution, each with their drawbacks. It can also be done using iterative methods like OI or Schweighofer's algorithm, which at no point calculate the homography matrix, but just use the corresponding points and which require an initial estimation (for which the initial guess from a homography decomposition could be used).
With only four points your solution will be normally very sensitive to small errors in their location, particularly when the rectangle is nearly orthogonal to the optical axis (this is because the vanishing points are not observable - they are outside the image and very far from the measurements - and the pose is given by the cross product of the vectors from the centre of the quadrangle to the vanishing points).
Is your pattern such that the corners can be confidently located with subpixel accuracy? I recommend using "checkerboard-type" patterns for the corners, which allow using a good and simple iterative refining algorithm to achieve subpixel accuracy (look up "iterative saddle points algorithm", or look up the docs in OpenCV).
I will not provide you with a full answer, but it looks like at least one of the points that need to be clarified is this:
homography is an invertible mapping from P^2 (homogeneous 3-vectors) to itself, which always may be represented by an invertible 3x3 matrix. Having said that, note that if your 3d points are coplanar you will always be able to use homography to relate the world points to the image points.
In general, a point in 3-space is represented in homogeneous coordinates as a 4-vector. Projective transformation acting on P^3 is represented by a non-singular 4x4 matrix (15 degrees of freedom, 16 elements minus one for overall scale).
So, the bottom line is that if your model is planar, you will be able to get away with a homography (8 DOF) and an appropriate algorithm, while in general case you will need to estimate 4x4 matrix and would need a different algorithm for that.
Hope this helps,
Alex
I'm working on the analysis of a particle's trajectory in a 2D plane. This trajectory typically consists of 5 to 50 (in rare cases more) points (discrete integer coordinates). I have already matched the points of my dataset to form a trajectory (thus I have time resolution).
I'd like to perform some analysis on the curvature of this trajectory, unfortunately the analysis framework I'm using has no support for fitting a trajectory. From what I heard one can use splines/bezier curves for getting this done but I'd like your opinion and/or suggestions what to use.
As this is only an optional part of my work I can not invest a vast amount of time for implementing a solution on my own or understanding a complex framework. The solution has to be as simple as possible.
Let me specify the features I need from a possible library:
- create trajectory from varying number of points
- as the points are discrete it should interpolate their position; no need for exact matches for all points as long as the resulting distance between trajectory and point is less than a threshold
- it is essential that the library can yield the derivative of the trajectory for any given point
- it would be beneficial if the library could report a quality level (like chiSquare for fits) of the interpolation
EDIT: After reading the comments I'd like to add some more:
It is not necessary that the trajectory exactly matches the points. The points are created from values of a pixel matrix and thus they form a discrete matrix of coordinates with a space resolution limited by the number of pixel per given distance. Therefore the points (which are placed at the center of the firing pixel) do not (exactly) match the actual trajectory of the particle. Either interpolation or fit is fine for me as long as the solution can cope with a trajectory which may/most probably will be neither bijective nor injective.
Thus most traditional fit approaches (like fitting with polynomials or exponential functions using a least squares fit) can't fulfil my criterias.
Additionaly all traditional fit approaches I have tried yield a function which seems to describe the trajectory quite well but when looking at their first derivative (or at higher resolution) one can find numerous "micro-oscillations" which (from my interpretation) are a result of fitting non-straight functions to (nearly) straight parts of the trajectory.
Edit2: There has been some discussion in the comments, what those trajectories may look like. Essentially thay may have any shape, length and "curlyness", although I try to exclude trajectories which overlap or cross in the previous steps. I have included two examples below; ignore the colored boxes, they're just a representation of the values of the raw pixel matrix. The black, circular dots are the points which I'd like to match to a trajectory, as you can see they are always centered to the pixels and therefore may have only discrete (integer) values.
Thanks in advance for any help & contribution!
This MIGHT be the way to go
http://alglib.codeplex.com/
From your description I would say that a parametric spline interpolation may suit your requirements. I have not used the above library myself, but it does have support for spline interpolation. Using an interpolant means you will not have to worry about goodness of fit - the curve will pass through every point that you give it.
If you don't mind using matrix libraries, linear least squares is the easiest solution (look at the end of the General Problem section for the equation to use). You can also use linear/polynomial regression to solve something like this.
Linear least squares will always give the best solution, but it's not scalable, because matrix multiplication is moderately expensive. Regression is an iterative heuristic method, so you can just run it until you have a "sufficiently good" answer. I've seen guidelines for the cutoff at about 1000-10000 dimensions in your data. So, with your data set, I'd recommend linear least squares, unless you decide to make them highly dimensioned for some reason.
I'm looking at the CUDA SDK convolution with separable kernels, and I have a simple question but can't find an answer:
Do the vectors, whose convolution gives the kernel, need to have the same size? Can I first perform a row-convolution with a vector 1x3 and then a column convolution with another one 5x1 ? Or they both need to be same size? Google isn't helping (or I'm unable to search for an answer)
Yes, the vectors can be different sizes. The only consequence is that you'll get a rectangular matrix that is not square.
The vectors of a separable convolution could only be different sizes if the equivalent convolution matrix was not square.