LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scale/Bin a 2-D Array

Has anyone scaled or binned a 2-D array before?  If so, could you give some information on your method?
 
Example of problem:
                                    initial array                 scaled array (skipped every other)
scale array by 50%:    1   1   2   2                   1   2
                                    1   1   2   2                   3   4
                                    3   3   4   4
                                    3   3   4   4
 
                                    initial array                 binned array (averaged in quads)
bin by 2 array:             1   2   2   3                   2.5   3.5
                                    3   4   4   5                   4.5   5.5
                                    3   4   4   5
                                    5   6   6   7
 
Thanks!
0 Kudos
Message 1 of 10
(4,704 Views)

You could probably use the image resizing VI found here for the scaling (note that it gets slow for large arrays).

For the averaging, you can probably do something similar to what I demonstrated in the "Test.vi" in the attachment here.


___________________
Try to take over the world!
0 Kudos
Message 2 of 10
(4,694 Views)

2D bin data.png

 

"Decimate (single shot).vi" will give you a binning in one dimension if you set the "averaging" to TRUE. So you can run this on all of the rows, then on the resultant columns.

0 Kudos
Message 3 of 10
(3,677 Views)

(Wow, this was an very old thread (>>10 years!)  you revived here! :D)

 

Here's what I would probably do (but probably more scalable so a reduction factor is an input and sanity checks are performed if the input sizes are not correctly divisible).

 

DecimateOrAverage2D.png

Message 4 of 10
(3,663 Views)

I like your solution.  Should be faster.

0 Kudos
Message 5 of 10
(3,625 Views)

@D* wrote:

 

"Decimate (single shot).vi" will give you a binning in one dimension if you set the "averaging" to TRUE. So you can run this on all of the rows, then on the resultant columns.


scale_binning_2d-array.png

For the "Input bin" and averaging=false you will get the same result, as for averaging=true.

 

But, for the "Input averaging" and averaging=false you will get different results.

 

 

0 Kudos
Message 6 of 10
(3,613 Views)
-
0 Kudos
Message 7 of 10
(3,613 Views)

Hey. In case anyone else encounters the need to bin 2d arrays, i made this VI :

You can also bin separately along X and Y axis. In case the bin value does not exactly divide array size, it acts as if zeros were added.

 

DrAdrien_0-1632827496750.png

 

0 Kudos
Message 8 of 10
(2,564 Views)

Hey. For the binning case on 2d arrays, i started from the answer below and extended the case to independant X-Y binning, and binning values different than 2. In case anyone else encounters the need to bin 2d arrays, feel free to use this VI :

 

DrAdrien_0-1632827496750.png

 

0 Kudos
Message 9 of 10
(2,565 Views)

Hi Adrien,

 


@Dr.Adrien wrote:

In case anyone else encounters the need to bin 2d arrays, feel free to use this VI :


Even as you posted the very same message twice in different threads you failed to provide that VI with both messages!

All we got from you are two images, but no VI. Not even a snippet…

 

(Please clean up the VI before attaching the real code.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 10
(2,552 Views)