1. Click Binary»Adv. Morphology or click Adv. Morphology in the Binary tab of the Processing Functions palette.
  2. Select Remove small objects.
  3. Specify the number of 3 x 3 erosions that need to be applied to completely remove a small object in Iterations.
  4. Click OK to remove small objects and add this step to the script.