# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

## Average every two neighbours through array

Dear All,

I have an 2D array and I would like to average every two values in each line.

For example an incoming array (sizeX=16,sizeY=8) will result into an outcoming array of 8x8.

I have implemented this already, but I was wondering whether you could suggest me a faster way of doing so?

In the Example below the incoming 2D array has a dimension of 768x1536 and the out coming 2D array has a dimension of 768x768.

AverageTwoNeighbours

Thanks a lot!

Message 1 of 5
(385 Views)
Highlighted
Solution
Accepted by topic author Kenai23

## Re: Average every two neighbours through array

You can try something like this if you have an even number of points in each row.

mcduff

Message 2 of 5
(364 Views)
Highlighted

## Re: Average every two neighbours through array

Yes, decimate the array and do the averaging outside the array. You can convert it to U16 at the end if you need it to be an integer.

Try and do as much as possible outside the array to reduce redundency.

Message 3 of 5
(348 Views)
Highlighted

## Re: Average every two neighbours through array

1. It is not clear if you are averaging along rows or along columns or along both or along either.  Your original description says an incoming 16 x 8 array results in an 8 x 8 array (so you are averaging pairs of rows), but your example says a 768 x 1536 array results in a 768 x 768 array (averaging pairs of columns).  Please clarify.
2. I was wondering about the adding of 0.5 after the average (why not use the Mean VI on the Math Palette?).  Then I realized you were just doing "rounding" (which would happen automatically when you changed from Float to Integer, or you could use one of the three explicit Rounding functions from the Numeric Palette and make your intention clear).

I think McDuff's suggestion of using Decimate and Average is a good one, but (again) you need to clarify if you are combining rows or columns (McDuff's code combines columns, of course).  And don't "hide" the rounding function.

Bob Schor

Message 4 of 5
(334 Views)
Highlighted