LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Moving average of 2d array (image).

Solved!
Go to solution

Simple program for moving average. It extend border of array and apply filter (square with chosen length  mean at each point). Then it come back to initial size.

Download All
0 Kudos
Message 1 of 5
(5,456 Views)
Solution
Accepted by BrainBurn

There is a place for example programs.

 

Looking at the code for a nanosecond:

  • "Index array" is resizeable
  • It is extremely annoying if the front panel and diagram is maximized to the screen.
  • To create a border (why?), it is much more efficient to initialize a zeroed array at the larger size followed by "replace array subset" at the offset position. no need to all that array gymnastics in your subVI.
  • My idea of a moving average of 2D arrays is something completely different. Please explain what you are actually trying to do here. Looks more like a convolution with a square kernel that could be done much easier. Can you show an image?
Message 2 of 5
(5,445 Views)

1. That would provide different result.

2. Do not got that point.(generally that is sub-VI, I do no care about front panel). That was for testing.

3. Agree, replace would work faster.

3. Moving average is the convolution with squire or circle with constant matrix. I though that my code would work faster. At that case. But I like using convolution, it could make any type of filter from my code. Thanks!

Any array would work for me.

That is an actual example.

Thank you for your comments!

P.S. I planned to exchange http://www.ni.com/example/26681/en/ with repeating border padding.

0 Kudos
Message 3 of 5
(5,427 Views)

@BrainBurn wrote:

1. That would provide different result.

2. Do not got that point.(generally that is sub-VI, I do no care about front panel). That was for testing.

3. Agree, replace would work faster.

3. Moving average is the convolution with squire or circle with constant matrix. I though that my code would work faster. At that case. But I like using convolution, it could make any type of filter from my code. Thanks!

 


 

  1. What is "that"?
  2. What "point"?

A convolution based approach gives the same result*, here's a quick example. But test for yourself! (The length here is manipulated to give the same result as with your "length" definition.

 

*Note that there are differences near the edges of the result, because the convolution truncates while you bunch the outside values into the boundary values. Not sure what is more desirable.

 

Convolution.png

 

 

(Even if you do it explicitly, you don't need the padding if done correctly.)

 

What does the attached csv file have to do with the question? Is that in input? result? Something else?

0 Kudos
Message 4 of 5
(5,412 Views)

@altenbach wrote: 

(Even if you do it explicitly, you don't need the padding if done correctly.)

 


Just for fun, Here is a direct comparison of the stock convolution and an explicit mimic that gives the same result. This is useful if you only have "LabVIEW base" where the convolution tools are not included.

 

As I said, no padding needed because indexing outside an array just returns zero (you cannot use that method for "array subset", of course).

 

The code could be significantly optimized for inplaceness and the outer loop could even be parallelized. This is just a very rough draft. There are many other (even better) ways to do it, of course.

 

Convolution2.png

Message 5 of 5
(5,397 Views)