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: 

Particle Filter 3 - How to filter particles satisfying ALL criteria?

Solved!
Go to solution

I am trying to filter a binary image to only keep particles that satisfy ALL of my desired criteria (e.g. within a specified range of Area AND Perimeter). The Particle Filter 3 vi keeps particles that satisfy ANY of the criteria (e.g. Area is in range but perimeter is out of range). Do I need to loop on Particle Filter for each criteria or is there another way to do this?

 

Thanks,

--Dave

0 Kudos
Message 1 of 5
(2,573 Views)

Hi,

 

no, use the "Keep/Remove Particles" property and the "Exclude/Include" bool for the limits.


Example: You want to remove any particle with

an area from 0-100
AND a perimeter from 100-1000.

 

To do so, KEEP any particle that has

- an area from 101-+Inf
- a perimeter from 0-100
- a perimeter from 1000 - +Inf.

 

Birgit

0 Kudos
Message 2 of 5
(2,547 Views)

Thank you, Birgit.

 

My original implementation was intended to KEEP particles that were within both Area and Perimeter limits.

 

Example: KEEP particles with Area from 100 to 200

AND Perimeter from 50 to 75.

 

I set my selection value measurements to:

   Meas Param=Area, Range Lower=100, Range Upper=200, Range=False (IMAQ Particle Filter 3 VI particle meets the criteria if Range Lower Value ≤ particle measurement < Range Upper Value)

  Meas Param=Perimeter, Range Lower=50, Range Upper=75, Range=False

 

In Particle Filter I set Keep/Remove to False (only particles meeting any of the criteria remain)

 

In my image I had 2 particles:

    1: Area = 150, Perimeter = 70

    2: Area = 25, Perimeter = 50

 

The result was that both particles were kept, even though particle 2 was outside the Area criteria. I don't understand why.

I then changed my implementation to EXCLUDE particles outside the Area and Perimeter ranges as follows:

I set four selection value measurements to:

   Meas Param=Area, Range Lower=0, Range Upper=100, Range=False

   Meas Param=Area, Range Lower=100, Range Upper=+Inf, Range=False

   Meas Param=Perimeter, Range Lower=0, Range Upper=50, Range=False

   Meas Param=Perimeter, Range Lower=75, Range Upper=+Inf, Range=False

 

In Particle Filter I set Keep/Remove to True (particles meeting any of the criteria are removed)

This implementation works. Can you explain why my first implementation did not? I would like to understand just how the tool works.

 

Thanks,

--Dave

0 Kudos
Message 3 of 5
(2,534 Views)
Solution
Accepted by topic author mpu

Hi,

I am not from NI so I don't see the internal implementation. However, I stumbled upon that when I quickly looked up the parameter in the help before I typed my initial answer. 

 

Correction of my previous answer, I was on my mobile and didn't read too closely.

 

You correctly identify that Particle Filter tries "any" condition, aka an OR condition.

 

Case 1:
1) Keep anything that is are 100-200
2) ALSO keep anything that is perimeter 50-75.

 

Case 2:
1) Remove anything that is area 0-100
2) Remove anything that is area 200-Inf
3) Remove anythng that is perimeter 0-50
4) Remove anything that is perimeter 75-Inf

 

It seems to do that sequentially.
 

Birgit

Message 4 of 5
(2,531 Views)

Thanks, Birgit. Your explanation for the second case that the tests are sequential and OR'd makes sense.

It does seem like a sloppy way of doing things but if I understand how it works then I can deal with. As you said, no loop is needed.

 

Thanks!

--Dave

0 Kudos
Message 5 of 5
(2,520 Views)