LabVIEW

cancel
Showing results for
Did you mean:

2-D image averaging

My 16-bit ADC supplies a stream of "Raw 1D I16" data at 1MS/s to fill a 2-D array to form an image at a rate of 4 frames/sec. To get a better image I have to average 10 frames before displaying it to the monitor and then storing this "averaged" 16-bit image array. I need all 16 bits for image post-processing. I don't have IMAG Vision for sophisticated image acquisition and manipulation. What is the most efficient way to do averaging when the stream of data is coming continuously to fill the 2-D array?

Message 1 of 6
(2,625 Views)

Re: 2-D image averaging

Hello,

I wouldn't be worried about "the most efficient way" at this point.

Just get your image averaging down so you know it's working the way you want it to.  Then graduate to refining your algorithm and code.

To start, if you're getting your images one at a time, you can just scale them by the number you want to average and add them, keeping a running total which will be your average upon completion.

For example, if I know I am going to average 3 values (say a, b, and c), and I get them "one at a time", I just keep a running total to compute the average in pieces as follows:

initial total value:
0

first iteration (recieve a):
new total value = previous value + a/3 = 0 + a/3

new total value = previous value + b/3 = a/3 + b/3

new total value = previous value + c/3 = a/3 + b/3 + c/3

Clearly and trivially you can see that the final result is the average of a, b, and c.

The reason I suggest it this way is that if you are receiving the images one at time, this way you only have to manage two arrays in memory - the "previous value" which is the running total, and the value you receive on that iteration.

You could just get all the images you want to average first, and then perform the average operation on them all at once, but then you have to store all the images you want to average at the same time.  On the other hand, doing it this way would cause you to only have to perform a single division operation (add them all up and then divide), instead of performing the division on each piece separately.  For a 2D array the division is performed on each element of course, but the idea still holds.

However, if you need to do weighted averaging at some point, then you'll have to do a "piece-wise" averaging anyway.  Further, doing the average in pieces as suggested allows you to store less data in memory at a given time, but still compute the average as you receive your images - you just have to know how many you are receiving and want to average.

In LabVIEW, you can keep your "running total" in a shift register.

There are other ways to complete your task - precisely what is most efficient for you will really depend on how you are receiving the data - do you receive entire images at a time, or single pixels at a time, or multiple images at a time, or something inbetween those... that information will affect the optimal way to process it in addition to other factors (some discussed above, such as how many of a given computation type is required).  Then there is optimization you can do in LabVIEW for memory and performance.

To round out this post, I suggest you pick something "reasonable" to start, and then refine later as needed.

I hope this helps!

Best Regards,

JLS

Best,
JLS
Sixclear
Message 2 of 6
(2,591 Views)

Re: 2-D image averaging

Good idea! JSL, thanks for the suggestions. Let me start coding and see how it works. Thanks.

Message 3 of 6
(2,583 Views)

Re: 2-D image averaging

Convert to I32. Add the 10 frames. (Running sum with shift register as data comes in?) Integer divide by 10. Convert back to I16.

This should have minimal concerns about roundoff errors and should be fast since all calculations are done with integers and only divide once.

Lynn
Message 4 of 6
(2,579 Views)

Re: 2-D image averaging

Hi JLS and Lynn,

I have successfully written the VI to do 2-D image averaging according to your insights. Thanks.

Larry

Message 5 of 6
(2,531 Views)

Re: 2-D image averaging

Excellent!

Thanks for the update!  If it's something others in the community could use (not too specific to your application) you may consider posting the VI here!

Either way, glad you have what you need 🙂

Best Regards,

JLS

Best,
JLS
Sixclear
Message 6 of 6
(2,520 Views)