LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average every two neighbours through array

Solved!
Go to solution

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.

 

AverageTwoNeighboursAverageTwoNeighbours

 

Thanks a lot!

 

 

0 Kudos
Message 1 of 5
(2,293 Views)
Solution
Accepted by topic author Kenai23

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

 

mcduff

 

Snap1.png

Message 2 of 5
(2,272 Views)

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.

[Architect]

0 Kudos
Message 3 of 5
(2,256 Views)

First, two comments on your description of your problem and your code:

  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

 

0 Kudos
Message 4 of 5
(2,242 Views)

Thanks a lot for your solution. It was very helpful.

0 Kudos
Message 5 of 5
(2,186 Views)