LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort XY by closest

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 :

LabVIEW.png

 

 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

Download All
0 Kudos
Message 1 of 21
(5,822 Views)

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.

Greets, Dave
Message 2 of 21
(5,807 Views)

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.

 

labview2.png

 

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.

0 Kudos
Message 3 of 21
(5,791 Views)



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:

2013-05-28_2d-to-1d.PNG

 

 

 


Alex

Message 4 of 21
(5,777 Views)

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

0 Kudos
Message 5 of 21
(5,755 Views)
Message 6 of 21
(5,740 Views)

 

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: 

 

2013-05-29_2dsort.png

 

result.PNG

 

 

 

 

 

Alex

 

Message 7 of 21
(5,727 Views)

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

0 Kudos
Message 8 of 21
(5,711 Views)

 

could you post a more advanced example as a .csv file?

 

Message 9 of 21
(5,708 Views)

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

0 Kudos
Message 10 of 21
(5,694 Views)