Get connected points (edges) from a d-dimensional Delaunay Triangulation in CGAL - triangulation

I have a set of points. I want to calculate the Delaunay Triangulation of them using CGAL and then get the neighbors back.
Input:
p1, p2, p3, p4, ...
Output:
p1-p2, p1-p4, ....
I found answers to this problem for 2 or 3 dimensions. However I need have at least 6-8 dimensions. I can't figure it out. The proposed answers for lower dimensions use edges_iterator. This isn't implemented for d-dimensions. The documentation isn't helping me either...
update:
What I have so far is this, sadly it results in a segfault after some iterations
T t(D);
t.insert(points.begin(), points.end());
for(t_iterator ei = t.finite_full_cells_begin(); ei != t.finite_full_cells_end(); ++ei) {
for (v_iterator vi = *ei->vertices_begin(); vi != *ei->vertices_end(); ++vi) {
std::cout << *vi << std::endl;
}
}
update2:
I ended up using scipy's triangulation instead. Much easier to use and better documented in my opinion

Cells have links to their vertices and every edge is part of a cell, so you can iterate on the cells and derive a list of edges (with redundancy). Note that if you only need the Delaunay graph, in high dimension, it may be faster to test for each pair of points if they form a Delaunay edge using linear programming.

Here are two papers that propose linear programming techniques to compute the Delaunay graph (pairs of adjacent Voronoi cells). It is very likely that CGAL cannot compute Delaunay in more than about 6 dimensions because it computes the full triangulation (edges, triangles, tetrahedra...).
A method for examining vector quantizer structures. Agrell IEEE 1993
Efficient Computation of Voronoi Neighbors based on Polytope Search in Pattern Recognition. ICPRAM2012

Related

How to compute distance and estimate quality of heterogeneous grids in Matlab?

I want to evaluate the grid quality where all coordinates differ in the real case.
Signal is of a ECG signal where average life-time is 75 years.
My task is to evaluate its age at the moment of measurement, which is an inverse problem.
I think 2D approximation of the 3D case is hard (done here by Abo-Zahhad) with with 3-leads (2 on chest and one at left leg - MIT-BIT arrhythmia database):
where f is a piecewise continuous function in R^2, \epsilon is the error matrix and A is a 2D matrix.
Now, I evaluate the average grid distance in x-axis (time) and average grid distance in y-axis (energy).
I think this can be done by Matlab's Image Analysis toolbox.
However, I am not sure how complete the toolbox's approaches are.
I think a transform approach must be used in the setting of uneven and noncontinuous grids. One approach is exact linear time euclidean distance transforms of grid line sampled shapes by Joakim Lindblad et all.
The method presents a distance transform (DT) which assigns to each image point its smallest distance to a selected subset of image points.
This kind of approach is often a basis of algorithms for many methods in image analysis.
I tested unsuccessfully the case with bwdist (Distance transform of binary image) with chessboard (returns empty square matrix), cityblock, euclidean and quasi-euclidean where the last three options return full matrix.
Another pseudocode
% https://stackoverflow.com/a/29956008/54964
%// retrieve picture
imgRGB = imread('dummy.png');
%// detect lines
imgHSV = rgb2hsv(imgRGB);
BW = (imgHSV(:,:,3) < 1);
BW = imclose(imclose(BW, strel('line',40,0)), strel('line',10,90));
%// clear those masked pixels by setting them to background white color
imgRGB2 = imgRGB;
imgRGB2(repmat(BW,[1 1 3])) = 255;
%// show extracted signal
imshow(imgRGB2)
where I think the approach will not work here because the grids are not necessarily continuous and not necessary ideal.
pdist based on the Lumbreras' answer
In the real examples, all coordinates differ such that pdist hamming and jaccard are always 1 with real data.
The options euclidean, cytoblock, minkowski, chebychev, mahalanobis, cosine, correlation, and spearman offer some descriptions of the data.
However, these options make me now little sense in such full matrices.
I want to estimate how long the signal can live.
Sources
J. Müller, and S. Siltanen. Linear and nonlinear inverse problems with practical applications.
EIT with the D-bar method: discontinuous heart-and-lungs phantom. http://wiki.helsinki.fi/display/mathstatHenkilokunta/EIT+with+the+D-bar+method%3A+discontinuous+heart-and-lungs+phantom Visited 29-Feb 2016.
There is a function in Matlab defined as pdist which computes the pairwisedistance between all row elements in a matrix and enables you to choose the type of distance you want to use (Euclidean, cityblock, correlation). Are you after something like this? Not sure I understood your question!
cheers!
Simply, do not do it in the post-processing. Those artifacts of the body can be about about raster images, about the viewer and/or ... Do quality assurance in the signal generation/processing step.
It is much easier to evaluate the original signal than its views.

Epipolar lines with known rotation and translation

I want to calculate the epipolar lines for the interest points between two images. I am working on a fountain dataset, so I have the rotation and translation matrix, as well as the camera matrix. I currently use Matlab in order to be fast, but the version I have is quite old(2009).
I am calculating the essential matrix through E=t*R and then the epipolar line with l=E*P, where P is the interest point/set of interest points. Then I get a vector with three lines which I guess are the line parameters of ax+by+c=0. The epipolar line drawn on the right image is totally wrong, far away from the point on the left image. Any idea???
Edit: Used dataset --> fountain benchmark, images 0000 and 0001 http://cvlabwww.epfl.ch/~strecha/multiview/denseMVS.html
Output: Essential matrix e.g. for point P1=[433.36;861.15;1]
E =
0.761857065048902 1.969487475012598 40.418915885686594
-0.927781947178923 0.698934833377211 33.173562943087106
-45.044061511303227 -26.573128396975097 1.000000000000000
It has two complex eigenvalues that are conjugated.
Epipolar line:1.0e+004 *
0.206660143270238
0.023299771007641
-4.240274401559348
Finally I found the solution to my problem. I post it here in case somebody else is interested.
To calculate correctly the relative rotation and translation matrices, the Roto-Translation matrix has to be used. This matrix is a 4x4 matrix for every image. The upper left part is the rotation (wrt the world coordinate system), the 4th sub-column is the translation vector (wrt to the world coordinate system) and the last row is [0 0 0 1]. So, if we have 2 such matrices for 2 images, the final roto-translation matrix is Qright-->left=inv(Qright)*Qleft. From this matrix, we extract the relative translation (t) and rotation(R) (4th sub column and upper left matrix respectively). Then, we create the skew symmetric matrix T for translation. The epipolar matrix is E=R*T. But this isn't enough. In order to calculate correctly the epipolar lines, the Fundamental matrix F has to be found. For a given dataset such the one I used, camera matrices K are given so this is easy: F=inv(Kright')*E*inv(Kleft), where (') is the transposed and inv is the inverted matrix. Then, the epipolar lines of the right image are calculated lines=F*P, where P is the point in homogeneous coordinates.
Thank you!
There are lots of documents that can found online that explain epipolar geometry and how to find epipolar lines in stereo images. Here is one. It walks you through different concepts decently. The trick to this topic, I found, is keeping track of the variables which are ultimately the result of matrix transformations and implied (professor shortcuts) algabraic operations.
My recommendation would be looking at page 12 of the link I've provided and applying it your scenario. Without any data to go off of other than the description you've provided, it's impossible to work out the problem.
Good luck.
Note: sorry to hear your Matlab version is old. I know that 2013 has built in functions for this stuff, but I'm not sure if 2009 does because MathWorks requries an account to read older documentation.

Gridding non-uniformly sampled data to a uniformly spaced Cartesian grid via convolution

I am trying to re-grid non-uniform data onto a uniform grid defined in a 4-D space. The data measurement is given by a function d = f(xp,yp,zp,wp), where xp, yp, zp, and wp are the 4-D coordinates. I would like to re-grid the non-uniformaly spaced xp, yp, zp, and wp onto a uniformly spaced grid of x, y , z, and w.
For ease of conversation, let's define the gridding kernel to be the product of separable Hanning kernels:
1/a(1+cos(2*pi*x/a))
1/b(1+cos(2*pi*y/b))
1/c(1+cos(2*pi*z/c))
1/d(1+cos(2*pi*w/d))
Then, I believe to re-grid what I need to do is perform a 4-D convolution and resample onto the uniform grid. However, I'm not sure how to implement this using discrete data. My questions are as follows:
1) How should I sample each of the gridding kernels? For example, should I use the non-uniform xp, yp, zp, and wp values when calculating my discrete convolution values? Or should I use the uniformly spaced values, x, y, z, and w? Or are neither of those ideas correct?
2) How can I then implement the 4-D convolutions? I think I may need to use four for loops but am not exactly sure how to organize my data, i.e., a 4-D data structure or simply a matrix with 4 columns?
I'm not interested in the fastest approach but more so in finding the most intuitive or straight forward approach.
I believe I understand the basics of sinc interpolation and gridding algorithms. I have read multiple papers including such classics by J.D. O'Sullivan and J.I. Jackson, discussing the properties and differences in different gridding kernels. I've also read some papers from MRI reconstruction that use gridding but most of these methods assume a 2-D grid.
I am at a loss of how to actually implement the method, preferably in Matlab, or else C++, in a discrete manner and even more confused how to implement such a thing in four dimensions.
I've looked at several threads and my problem is somewhat similar to these, however I want to use convolution with a general kernel, not linear interpolation, and neither of these really suggest how to organize the 4-D data or perform the convolution:
Python 4D linear interpolation on a rectangular grid
Python 4D linear interpolation on a rectangular grid
Thanks for any advice, insight, or suggestions!
Can you use the interpn function?
[X Y Z W]=ndgrid(x,y,z,w); % unequally spaced
[XR YR ZR WR]=ndgrid(x_regular,y_regular,z_regular,w_regular); % equally spaced
volume=interpn(X,Y,Z,W,d,XR,YR,ZR,WR);
The documentation for interpn and ndgrid give more details; their usage would give you a framework for how to construct d.
EDIT: Oh sorry sorry, I saw your comment about not wanting to use interpolation after posting this.
Well, you could use interpolation as above to position your values onto the grid linearly, and then use
volume=convn(volume,general_kernel);
To convolve the values with your kernel?

Matlab image centroid simulation

I was given this task, I am a noob and need some pointers to get started with centroid calculation in Matlab:
Instead of an image first I was asked to simulate a Gaussian distribution(2 dimensional), add noise(random noise) and plot the intensities, now the position of the centroid changes due to noise and I need to bring it back to its original position by
-clipping level to get rid of the noise, noise reduction by clipping or smoothing, sliding average (lpf) (averaging filter 3-5 samples ), calculating the means or using Convolution filter kernel - which does matrix operations which represent the 2-D images
Since you are a noob, even if we wrote down the answer verbatim you probably won't understand how it works. So instead I'll do what you asked, give you pointers and you'll have to read the related documentation :
a) to produce a 2-d Gaussian use meshgrid or ndgrid
b) to add noise to the image look into rand ,randn or randi, depending what exactly you need.
c) to plot the intensities use imagesc
d) to find the centroid there are several ways, try to further search SO, you'll find many discussions. Also you can check TMW File exchange for different implementations for that.

How to generate this shape in Matlab?

In matlab, how to generate two clusters of random points like the following graph. Can you show me the scripts/code?
If you want to generate such data points, you will need to have their probability distribution to be able to generate the points.
For your point, I do not have the real distributions, so I can only give an approximation. From your figure I see that both lay approximately on a circle, with a random radius and a limited span for the angle. I assume those angles and radii are uniformly distributed over certain ranges, which seems like a pretty good starting point.
Therefore it also makes sense to generate the random data in polar coordinates (i.e. angle and radius) instead of the cartesian ones (i.e. horizontal and vertical), and transform them to allow plotting.
C1 = [0 0]; % center of the circle
C2 = [-5 7.5];
R1 = [8 10]; % range of radii
R2 = [8 10];
A1 = [1 3]*pi/2; % [rad] range of allowed angles
A2 = [-1 1]*pi/2;
nPoints = 500;
urand = #(nPoints,limits)(limits(1) + rand(nPoints,1)*diff(limits));
randomCircle = #(n,r,a)(pol2cart(urand(n,a),urand(n,r)));
[P1x,P1y] = randomCircle(nPoints,R1,A1);
P1x = P1x + C1(1);
P1y = P1y + C1(2);
[P2x,P2y] = randomCircle(nPoints,R2,A2);
P2x = P2x + C2(1);
P2y = P2y + C2(2);
figure
plot(P1x,P1y,'or'); hold on;
plot(P2x,P2y,'sb'); hold on;
axis square
This yields:
This method works relatively well when you deal with distributions that you can transform easily and when you can easily describe the possible locations of the points. If you cannot, there are other methods such as the inverse transforming sampling method which offer algorithms to generate the data instead of manual variable transformations as I did here.
K-means is not going to give you what you want.
For K-means, vectors are classified based on their nearest cluster center. I can only think of two ways you could get the non-convex assignment shown in the picture:
Your input data is actually higher-dimensional, and your sample image is just a 2-d projection.
You're using a distance metric with different scaling across the dimensions.
To achieve your aim:
Use a non-linear clustering algorithm.
Apply a non-linear transform to your input data. (Probably not feasible).
You can find a list on non-linear clustering algorithms here. Specifically, look at this reference on the MST clustering page. Your exact shape appears on the fourth page of the PDF together with a comparison of what happens with K-Means.
For existing MATLAB code, you could try this Kernel K-Means implementation. Also, check out the Clustering Toolbox.
Assuming that you really want to do the clustering operation on existing data, as opposed to generating the data itself. Since you have a plot of some data, it seems logical that you already know how to do that! If I am wrong in this assumption, then you should word your questions more carefully in the future.
The human brain is quite good at seeing patterns in things like this, that writing a code for on a computer will often take some serious effort.
As has been said already, traditional clustering tools such as k-means will fail. Luckily, the image processing toolbox has good tools for these purposes already written. I might suggest converting the plot into an image, using filled in dots to plot the points. Make sure the dots are large enough that they touch each other within a cluster, with some overlap. Then use dilation/erosion tools if necessary to make sure that any small cracks are filled in, but don't go so far as to cause the clusters to merge. Finally, use region segmentation tools to pick out the clusters. Once done, transform back from pixel units in the image into your spatial units, and you have accomplished your task.
For the image processing approach to work, you will need sufficient separation between the clusters compared to the coarseness within a cluster. But that seems obvious for any method to succeed.