Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate the sumof image pixels?

Hi

 

I would like to calculate the sum of pixels of an image. Here is my code:

 

image2.jpg

 

I would like to ask if it exists another faster algorithm for sum calculation in labview. It seems that using C++ or Matlab this algorithm executes faster. In fact I would like to compare images according to their sum of pixels.

0 Kudos
Message 1 of 7
(6,299 Views)

The method you have demonstrated is probably the most inefficient.

 

In labview, you can just add the images together, or convert the images to arrays, and add the arrays together.  There is no need to go into for loops.

Machine Vision, Robotics, Embedded Systems, Surveillance

www.movimed.com - Custom Imaging Solutions
Message 2 of 7
(6,292 Views)

The simplest method is to use IMAQ Quantify.  It will give you the average intensity.  If you really want the sum, just multiply the average by the number of pixels.

 

Bruce

Bruce Ammons
Ammons Engineering
Message 3 of 7
(6,289 Views)

Hi,

 

Attached is a VI that shows different ways of doing computing the sum of the pixels of an image, with their respective benchmarks.

John is right. The fastest way is to use IMAQ Image to Array, cast the 2D array to double, then call the LabVIEW primitive Add Array Elements.

I's also like to point out a relatively new feature that we released about a year ago, which allows to access the image data in place, using the LabVIEW concept of Data Value Reference. There are VIs is Vision Development module that you can use to get a Data Value Reference of an image. When connected to an inplace structure, this allows you to get access to the pixels of the image directly, without having to make a copy (like it's the case with IMAQ Image to Array).

See example attached.

 

Hope this helps.

 

Best regards,

 

Christophe

Message 4 of 7
(6,284 Views)

Christophe's VI is useful, but one thing you shouldn't do is create an array and then convert the whole array to DBL, especially if your images can be large.  A better, and even faster, approach is to sum the U8 array into a DBL shift register like this:

 

Sum_BD.png

 

Really, this idea should be implemented, and then it wouldn't even be an issue.

Message 5 of 7
(6,225 Views)

Thanks, Greg.

You might get even better performances by enabling the outside loop iteration parallelism. (Right click on the For loop, then Enable Loop iteration parallelism).

 

Message 6 of 7
(6,220 Views)

Great solutions!

 

The only thing to note is that you cannot use parallel iterations because of the shift registers (using shift registers make one iteration depend on the previous one).

 

 

Andrew Valko
National Instruments Hungary
Message 7 of 7
(6,202 Views)