LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete equidistant indices in an array

Solved!
Go to solution

Hello everyone,

 

I have a performance problem. In my code, I use two nested for loops. The external one, runs 500 times every time. The internal one instead, runs one time for every pixel I find in a contour in a picture. Numbers can go from 10 to 1000. And 500x1000 is a lot of iterations. Besides, the difference between adyacent pixels is minimum so I don't need every pixel to build a contour.

So, I was thinking of letting only 50 pixels to define a contour and everytime I receive a certain number of pixels, use the "Delete from array" vi to reduce the amount of pixels to 50. But I would like to avoid any for loops, because, computational cost would raise the same if I need to go over the whole array. I.e. If I have 20 pixels and I want to reduce them to 10, I would pick indexes 1, 3, 5, 7, 9, 11, 13, 15, 17, 19.

I don't know if this is possible. Can you help me please?

 

I cheked this post:

http://forums.ni.com/t5/LabVIEW/Removing-a-list-of-indices-from-an-array/td-p/572652

but it isn't the same problem, plus it uses for loops, in fact, I would say mine is simplier to solve and maybe very trivial but I cannot find a solution.

 

Thanks in advance.

 

0 Kudos
Message 1 of 6
(2,433 Views)

You can use Decimate-1D array....

 

Decimate Array.png


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 2 of 6
(2,430 Views)
Solution
Accepted by topic author pakopon

Using Index Array inside a loop will produce the results you want and can work quite quickly.  The attached VI selects one element from every "Period" elements.  For test purposes I have two arrays, one of random DBL and another of sequential I32. The integer array allows quick verification that you are getting the arrays you want.

 

When used as a subVI with the panel closed, this averaged 33 microseconds with 1000 pixel arrays and periods of 50 or 100.  The tester loop ran ~200000 iterations before I stopped it to check the timing.

 

That translates to about 17 ms for your 500x1000 setup.

 

Lynn

Message 3 of 6
(2,400 Views)

Thanks both for your quick responses.

 

johnsold, I'm very impressed about the timings your code got. I've never thought huge loops could run so fast. Let's see how it works in my project. 

 

Thanks again.

0 Kudos
Message 4 of 6
(2,389 Views)

Loops are so ubiquitous in programming that NI has put much effort into assuring that loops have as little overhead as possible.  The code inside the loops - created by LV programmers like us - is what takes the time.

 

Some of the keys are to avoid creating unneeded data copies, avoiding memory re-allocations, avoiding the UI thread (no indicators or property nodes in the loop), no calls to the OS (file I/O for example), and so on.  Note that with 1000 pixels and a period of 50 the for loop in my VI only runs 20 times. So 20x500 = 10000 is not a large number of iterations.

 

Lynn

Message 5 of 6
(2,383 Views)

Thnaks, I'll keep that in mind.

0 Kudos
Message 6 of 6
(2,363 Views)