From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Integrate 2d array along one dimension (say row) to get 1 D column array

Dear everyone,

 

I have a 2D array. I want to integrate along one of the dimensions only which will result a 1D array after integration. Lets say I have a 2D array ((1,2,3), (2,1,3), (4,5,6)). If I integrate along row wih dt=1 it will result a 1D array (6,6,15). One can do so by spilitting the 2D array by 'index array' and then using '1D numerical integration' function. But it will take some time for a big array size to separately integrate one row after another. Is there any way to integrate along each row simultaneously so that it saves time?

 

Thanks in advance,

Somnath

0 Kudos
Message 1 of 8
(5,070 Views)

You are actually asking for the sum, not the integral.  You don't want the intermediate values, just the result.

 

You can loop through the 2D array and use Sum Array to quickly sum each line, which is probably the fastest way to do it.  Another option is to use IMAQ LinearAverages, which will give you the average of each row.  You can multiply by the number of points in each row to get the sum.

 

Bruce

Bruce Ammons
Ammons Engineering
Message 2 of 8
(5,066 Views)

What are you trying to do finally may be there will a direct function

0 Kudos
Message 3 of 8
(5,049 Views)

Basically, I convert image to array, which is a 2D array. Then I want to integrateout one dimension to get a line spectra. So basically its an addition of all elements of a row for a column index. Unfortuntely, I could not find the sum array function or IMAQ liner average VI what Bruce suggested. May be I miised to install portion of IMAQ. It will be very helpful if anyone can help me finding/installing IMAQ linear average VI.

 

Thank you

Somnath

0 Kudos
Message 4 of 8
(5,041 Views)

The sum array function is a basic math function on the math palette.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 5 of 8
(5,038 Views)

Hi Bruce,

Math pallet meaning inside mathematics right? May be I am missing something stupid, but I can not find even in giving search in function pallets search option.

 

Somnath

0 Kudos
Message 6 of 8
(5,036 Views)

Sorry, Add Array Elements in Numeric palette.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 7 of 8
(5,014 Views)

As suggested add array elements in a direct function that you use. Can you post an image before you convert it into an array?

0 Kudos
Message 8 of 8
(5,002 Views)