Statistical Methods

Decide Which Enclosed Background a Mask May Fill

Define the task

Hole filling changes the meaning of a binary mask. Begin with a copy and define whether an enclosed zero region is an unwanted omission or a genuine cavity. Record the foreground definition, array extent and connectivity. The teaching tool accepts synthetic 2-D grids and uses four-neighbor background connectivity: up, down, left and right. A diagonal touch alone does not create a path to the border.

Carry out the check

Trace background cells connected to the array boundary. Those remain background; unreachable zeros are the candidates for filling. Review changes against the analysis purpose before accepting them. Enlarging a connectivity footprint can cross thin barriers and change the result. A crop can also turn an enclosed cavity into border-connected background. Preserve both masks, the filled-cell count and the rule, rather than overwriting the original silently.

Worked hypothetical example

Hypothetical example: the rows [1,1,1], [1,0,1], [1,1,1] contain one enclosed zero, so filling adds one cell. Change the top-center value to zero and the center becomes connected to the exterior; now nothing should fill. This simple pair is a useful regression test. Filled area is not automatically more accurate segmentation, and this numerical operation cannot determine anatomy or disease.

Method checked 23 November 2026 against Primary method documentation: binary_fill_holes.

Open the enclosed mask hole audit.

Download the mask hole decision worksheet.

Related reading

Reading path: Analyze data. Guide 203 of 222. Choose any guide to suit your project.

Statistical Methods

Measure Distance to Background with the Correct Pixel Spacing

Practical steps and a hypothetical example: Measure foreground distance to sampled background using physical spacing.

Statistical Methods

Audit What a Morphological Opening Removes from a Mask

Practical steps and a hypothetical example: Check which mask features a declared morphology footprint removes.

Browse this reading pathTools for this stageGuides and downloads for this stage