LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Image Moment - Optimizing Code for Speed

Solved!
Go to solution

Hello Smiley Happy

 

I'm want to find the moment of inertia of an 2d-array. The array is converted from an image using "IMAQ ImageToArray".

 

 

The algorithm I'm using is discribed here:

Wikipedia - Image Moments

 

Image Moment.png

 

I need to calculate this formula with different values for i and j:

i.j = 0.0 - 0.1 - 1.0 - 1.1 - 0.2 - 2.0

 

I programmed the code shown above/attached VI, but I need the optimize it for speed.

The 2d array can be any size with a maximum of 2048 x 2048 with values varying between 0 and 4095.

 

 

My question:

How can I make this code faster?  Smiley Embarassed

 

 

 

 

Thank you and kudos will be given! Smiley Surprised

 

 

--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

0 Kudos
Message 1 of 27
(5,249 Views)

I think if you want good performance you should try to avoid the "Image to Array" and see if your processing doesn't exist in the IMAQ functions, open the Vission concepts manual in C:\Program Files\National Instruments\Vision\Documentation and search for moment the fews hits might be of interest to you.

 

Hope this helps


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 2 of 27
(5,241 Views)

Hello 

 

--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

0 Kudos
Message 3 of 27
(5,235 Views)

Is there someone who can help me optimize this code?

It is to slow for our application at the moment and I would be vey thankful for every optimize!

 

Smiley Tongue

--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

0 Kudos
Message 4 of 27
(5,196 Views)

Looking at the code I would try the following:

 

combine all of the operations that involve the transposed arrays into a single for loop.  same for the original arrays.  (ie. combine M10 and M20 loops as well as M01 and M02 loops)

 

parallelize the for loops (only the outer one for M11).

Message 5 of 27
(5,188 Views)
Solution
Accepted by topic author SectorEffector

You can speed it up about 60% just by combining some of your loops -- the calculation of M01 and M02, and M10 and M20, both share some computation.

 

Image Moment.png