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.