Object filtering


Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Remove objects from a label mask image.


Once objects have been identified in an image as a result of image segmentation, one often filters the objects based on certain measured criteria. For example, very small objects may be noise rather than real objects and could be removed.

Concept map

graph TD L("Label mask") -->|"remove label(s)"| ML("Modified label mask")


Object filtering. Left - Noisy labeled mask. Middle - Mask after removing border objects. Right - Mask after removing smaller objects (noise).


Show activity for:  

ImageJ GUI

  • Open the above mentioned image
  • [ Plugins > MorpholibJ > Label Images > Remove Border Labels ] to remove labels at the border
  • [ Plugins > MorpholibJ > Analyze > Analyze Regions ] to see area and number of objects
    • Using [X] Pixel Count. One can uncheck the rest of measurements
  • [ Plugins > MorpholibJ > Label Images > Label Size Filtering ] to remove smaller objects
    • Operation "Greater_than"
      • This will keep all objects greater than Size Limit (pixels)
    • Size Limit (pixels) 100

ImageJ Macro

run("Close All")

// File > Open

//  Plugins › MorphoLibJ › Label Images › Remove Border Labels
run("Remove Border Labels", "left right top bottom");

// Plugins › MorphoLibJ › Analyze › Analyze Regions
run("Analyze Regions", "area");

// Plugins › MorphoLibJ › Label Images › Label Size Filtering
run("Label Size Filtering", "operation=Lower_Than size=100");


Show exercise/solution for:

ImageJ GUI

  • Open xyz_16bit_labels_nuclei.tif
  • See if you have objects touching the borders, if yes, count them manually
  • Automatically remove the border objects
  • Check how many objects have been removed (Hint: generate measurement tables before and after border removal operation)


  • Scroll to the last slice of the image and check how many distinct labels you can find there (i.e. count = 13)
  • [Plugins › MorphoLibJ › Analyze › Analyze Regions 3D] (Note: [X] Voxel Count)
  • [Plugins › MorphoLibJ › Label Images › Remove Border Labels]
  • [Plugins › MorphoLibJ › Analyze › Analyze Regions 3D] (Note: [X] Voxel Count)
  • Compare the first columns of both the tables and count the entries. In the second table, there should be exactly 13 entries less than total number of entries in first table


True of false?

  1. In bioimage analysis, one should always remove all labels that touch the image boundary.
  2. The largest object has the highest label index.
  3. If you remove one object, the number of distinct labels decreases by one.


  1. Very often, but not always. Sometimes it also is an option to normalize downstream measurements by the visible size of objects.
  2. No, the label index usually has no meaning.
  3. Yes.

Discuss with your neighbor

  1. Is it a good idea to manually remove objects (labels) from an image or should this rather be an automated procedure?
  2. What are the pros and cons of removing labels from the image as opposed to keeping all of them and removing the corresponding object measurements later during statistical analysis of the measurement results?


  1. Automated typically is better as it forces you to define objective and reproducible criteria for which objects to remove.
  2. Pro: (i) Reduce computational load for further processing (e.g. morphological filters), (ii) Label mask image is easier to inspect visually (less clutter); Con: (i) You cannot check during analysis how your conclusions would have changed including those objects, (ii) …


Follow-up material

Recommended follow-up modules:

Learn more: