Machine Vision

Showing results for 
Search instead for 
Did you mean: 

Particle count on FPGA

Let's say I have a binary image on the FPGA. What's the best way to count how many particles are in the image? Is there a solution that keeps the image on the FPGA?


If the answer is "no", one option is to transfer the image to the CPU. Is the best option for image transfer to use a FIFO? I'm looking to minimize worst case latency. Image size is ~2000 pixels.


0 Kudos
Message 1 of 11

What do you know about the particles?  Are they convex all the way around?  Are they regular shapes?  How many might you see in a single row of pixels?


My initial thought is to scan each line of image, and keep track of starting and ending points of each particle.  Increase particle count if a new section is not touching section from previous line.  This only works if the particles are all convex, and only works if there is a limited number of particles per row.


It seems like you could store 2000 pixels in memory on the FPGA.  You can store and retrieve one value at a time.



Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 11

Particles are only a few pixels in area (like 10 px) so they can be rather irregular. I'm not expecting a very large number of px (maybe 5 or fewer)


I wasn't totally clear on what you meant by starting and ending point. I might need a diagram.


Here's a crop from a typical image with 3 particles.


0 Kudos
Message 3 of 11

I would probably use a variation of the image labeling routine.  This would require storing the previous line of the image, but that wouldn't be a big deal.


Start by scanning across each row.  If there is a pixel to the left, assign the current pixel the same value.  If no left pixel, check if there is a pixel above it and use that value.  Otherwise, increment your count and use that value.  If there is a pixel above it and there was a pixel to the left, if the values are different, increment your extra counter (only once per value).  At the end, subtract the extra from the count to get the correct count.


This is probably quite difficult to follow without a sketch and some examples.  Unfortunately I don't have time to do all that.



Bruce Ammons
Ammons Engineering
Message 4 of 11

Are you describing the two pass method here:

0 Kudos
Message 5 of 11

If you are using Vision Development Module from NI.

There is a function Partical Analysis Report  for FPGA.

Should be doing what you need.

I am working on NI PCIe-1477 and NI PCIe-1473R-LX110.

Seems like the function is available for both.

Did you review this function?

I attach the help for this function.


Amit Shachaf
0 Kudos
Message 6 of 11
0 Kudos
Message 7 of 11

I haven't tried yet. But usually you just need to count the number of elements in the array of measurements to get the partical number. 

Amit Shachaf
Message 8 of 11

I don't see an "array of measurements" as an output in the documentation.

0 Kudos
Message 9 of 11



That does look like what I was describing.  If you just want a count, you don't need the second pass.  You just need to count the extra labels and subtract that from the count at the end.



Bruce Ammons
Ammons Engineering
0 Kudos
Message 10 of 11