05-28-2013 08:18 AM - edited 05-28-2013 08:23 AM
Hi,
I'm currently facing a problem in LabVIEW array manipulation.
I'm using LabVIEW Vision VI called "IMAQ Count objects".
It's extracting me the XY of each objects at each frames. However, it doesn't track object frames by frame but simply "randomly" extract XY of each object on the frame.
This is why I would like to be able from row to row, to order every time each point by the previous closer one.
As it's not really easy to understand and my english level isn't good enough, here is an example done in excel :
Also,it's not simply "order every number" by ascending order, but it's XY coordinates.
I've also created a VI, in which I'm able to get :
- Difference between each X and Y at each frame
- From that, the distance between the 2 points
- Then order it by ascending order.
Maybe it can help ? So, I've attached my VIs.
Start OrderXYbyClosest.vi and put Distance2Points.vi in the same folder.
Please, don't say me it's a "Vision" problem, it's just array manipulation here that I want to do, not request a Vision feature 🙂
Thank you very much,
Sébastien
05-28-2013 09:24 AM
Hello Sebastien,
I didn't quite understand your example, but if you use complex numbers to calculate the distance between points, it should be the best way to sort your coordinates.
05-28-2013 10:23 AM - edited 05-28-2013 10:28 AM
Hi daveTW,
I'm sorry but my english level is good enough to correctly explain the problem, because even in my mothertongue, this isn't really easy to explain. I did an other example, this may be more helpful and understandable.
Hope someone can understand my problem 🙂
Thank you,
Sébastien
EDIT : But yes, I want to sort XY coordinates by closest row by row, but I'm just not able to do it 😞
The distance between 2 points isn't an important step if you can solve it in a an other way, but it was just an idea that might help to solve my problem?
I thought that the first step was to know which XY was the closer to the previous row XY; but there is probably an other way to do it.
05-28-2013 11:16 AM - edited 05-28-2013 11:17 AM
hi,
I don't know if I get you right, but here:
https://decibel.ni.com/content/docs/DOC-258872
are some sorting algorithms .VIs;
they all implemented for 1d arrays; you can use daveTW's suggestion to convert from 2d to 1d doing somthing like this:
Alex
05-29-2013 03:55 AM
Hi,
Your link doesn't seem to work.
And I don't really understand how complex might be helpful or not. I'm a bit lost.
Thank you,
Sébastien
05-29-2013 06:11 AM
05-29-2013 07:26 AM - edited 05-29-2013 07:28 AM
z = x + i*y
x ---> real part
y ---> imaginary part
e.g.:
x = 2 ; y = 3 --> z = 2 + i*3
z is a vector and the complex plane is an euclidian space;
so, if you calculate the absolute value of z, this is the same as calculating the position vector (distance from the vector's contact point (x,y) to the origin which is at 0,0 in this case)
Now, you just have to compare the position vectors of array A with array B:
Alex
05-29-2013 08:41 AM
Ok! Now I better understand why you are talking me about complex. Smart idea! -> Kudos 🙂
However, in my case, the number objects isn't especially 2, but is more something like 10 (or it can changes from one experiment to the other) and I feel like your code isn't automatisable for an undefined number of flies ?
I'll focus on it during this afternoon, but I feel like I'll be stuck on it.
Thank you,
Sébastien
05-29-2013 08:49 AM - edited 05-29-2013 08:56 AM
could you post a more advanced example as a .csv file?
05-29-2013 10:06 AM - edited 05-29-2013 10:08 AM
Of couse. Here is one with 3 objects and more coordinates. I've "created" it (from several different data I had).
One csv as requested - EDIT : I don't know why I'm not able to attach the csv one. Can you open the XLSX and save it to csv by yourself?
The same XLSX with the problem appeared highlighted in red.
As you can see, the VI scan each object starting from left to right (X axis), but if for example, the object #1 goes more to right than object #3, then object #1 will have the coordinates of objects #3 and vice versa.
I'm still working on your complex idea. I've even found this interesting VI http://zone.ni.com/reference/en-XX/help/371361J-01/gmath/sort_complex_numbers/ but I still have problems.
Thank you very much,
Sébastien