LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

arbitrary subarry

I would like to take a 2D rectangular array taken from an image and take a circle (approximately) from that array and make a subarray of that circle.  What I have written takes about a minute to run (the array is 495x652), and I wanted to know if there is an efficient way of doing it?  Or if this amount of time is reasonable for a 3GHz computer with 1GB of RAM. 
 
Currently, I use two For loops to raster the element indices to see if they fit the condition of being with the circle of radius "R" within the max element in the array.  Those within the radius go into one array, and the rest go into another. 
0 Kudos
Message 1 of 4
(2,767 Views)
Is the array size always 495x652 ?  If so you would realise a huge speed increase by precomputing an array to determine if or not a pixel is within the radius.  So instead of making all those expensive computations it would be a table lookup.
 
Another, possibly better alternative based on use, would be to also precompute an array of zeros and ones (just like the above solution) but AND the two arrays together to zero out all values outside the radius...
 
 
Just some ideas off the top of my head...
0 Kudos
Message 2 of 4
(2,763 Views)
OK, I played with this last night and during lunch today.  Tried a few different approaches but I think that this one works pretty well.  Take a look at it, see if you can piece it out to do what you need it to.  The biggest issue is the indexing of the output array.  If you are processing in a raster scan, then this should work pretty close out of the box.  I commented the code, but feel free to ask any questions that you may have.  Good Luck and a great processing puzzle.
Paul

Paul
0 Kudos
Message 3 of 4
(2,740 Views)
Thank you both.  Apparently what was causing most of the delay was the fact that I used a Formula panel to caluclate the circle instead of using the standard Labview math functions.  I will look at the vi's posted here to see if they are more elegant than what I have. 
0 Kudos
Message 4 of 4
(2,732 Views)