07-16-2009 09:56 AM
Thank you everyone for your help and time. Your solutions helped me create a program that I needed to average a 2-d array area as a function of the radius of the circle. Here is the code for anyone that is interested.
07-16-2009 11:01 AM
Sorry, but your code is very (very!) inefficient and orders of magnitude slower than it could be. To create the mask, all you need is sweep the square area and set the elements to zero or 1, depending on the distance from the center. Touch each potential element exactly once!
Even if you want to graph the temperature as a function of radius, you don't need to generate these huge data structures. Do everything "in place" in the first loop. For example keep two 1D arrays if size 2000, one for the count and one for the sum, and then accumulate histograms directly in one step, followed by division at the end.
You instead sweep in a circular motion with a fixed iteration count. In the first iteration (r=0), you are owerwriting the same element 2000 times, in the next iteration (r=1) things don't improve much and in the last iteration you might generate holes if the radius is too big. You are doing orders of magntude more operations than needed!
Don't use these gigantic diagram constants. Use "Initialize array" instead to make the code more readable. There is no penalty, because the code gets folded into a constant at compile time anyway.
Don't place controls and indicators inside the loops. The values are constant for the duration of the loop, so there is no need to poll the indicator 2000 times in a row for the same value.
Why don't you go back and study my example again, it's much better. 🙂
Also please add some real data to the VI so we can run it without guessing.
08-10-2009 03:38 PM
08-10-2009 05:47 PM
Here's the LabVIEW 8.2 version of my earlier code.
What do you mean by "outer edge"?
08-11-2009 12:10 PM
When I said outer edge I meant the edge of the circle at a certain radius. I am trying to break down the circle into discrete radii and average the values at each radii. I thought using a mask would be the best way to accomplish this since I couldn't think of a way to use a case structure. I figured since I'm only appoximating circles that mathmatically using a case structure would be difficult(maybe use a greater than and a less than check to see if the points lie between radii?). I am interested in your suggestions since I am running this code multiple times for a sequence of arrays so any improvement will definately be noticed.
I cleaned up my code a little, took away an extra for loop that was unnessesary. I had an idea to make the loop that breaks up the angles of the circle to be a function of the circles radius. But I am mediocre at math at best so I guess I'll just experiment with some exponential functions.
08-11-2009 02:57 PM
You are still running way too many iterations than warrented by the number of pixels in your image.
All you need to do is iterate over each pixel in the image, measure the distance to the center, and then make a histogram of average vs. r. Instead of averaging only one group as in my previous example, keep two 1D arrays, one to keep the sum(r) and one to keep the count(r), with the r mapped into the array index. At the end, divide the two 1D arrays to get the average as a function of distance.
08-11-2009 04:33 PM - edited 08-11-2009 04:34 PM
OK, here's a quick draft of what I had in mind (LV 8.2). Modify as needed.
(Move the center with the mouse to adjust).
08-12-2009 01:21 PM