Description
Apply a strict 3×3 binary majority filter with optional center inclusion and zero-valued outside neighbors.
A binary grid represents foreground as numeric one and background as zero. A stencil is a set of integer [rowOffset,columnOffset] positions relative to a cell. Connectivity describes allowed neighbor steps: four-neighbor connectivity uses orthogonal steps, while eight-neighbor connectivity also includes diagonals. Finite image borders and asymmetric stencils affect the result.
Apply a strict 3×3 binary majority filter with optional center inclusion and zero-valued outside neighbors.
When to use this tool
Use a strict local vote to remove sparse binary noise or compare center-including and center-excluding neighborhoods.
How to use the tool and how it works
- Enter mask, includeCenter using the definitions below.
- Run the operation. Resolve input-format errors before interpreting an output.
- Read result.mask, using the stated boundary, ordering, sign and absence conventions.
Count ones in the surrounding 3×3 neighborhood, including the center only when includeCenter is true. Set the output to one only if the count exceeds half of the fixed neighborhood size: nine including the center, eight otherwise.1
| Input field | Meaning and units | Accepted input |
|---|---|---|
| mask | Rectangular numeric 0/1 rows, up to 64×64; row is the first coordinate and column the second. | Dense numeric rows, each dimension at most 128; the stated shape rules also apply. |
| includeCenter | Whether the current cell participates in the fixed-size majority neighborhood: nine cells if true, eight if false. | Boolean true or false. |
| Output field | Interpretation |
|---|---|
| result | Object containing the fields below. |
| result.mask | Result grid in original frame dimensions, with numeric cell meanings and any signed subtraction convention described above. |
{
"input": {
"mask": [
[
0,
0,
0
],
[
0,
1,
0
],
[
0,
0,
0
]
],
"includeCenter": true
},
"output": {
"result": {
"mask": [
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
]
]
}
}
} Limitations and assumptions
- Outside-frame neighbors count as zero while the denominator remains nine or eight. Ties become zero, so edge behavior differs from a majority over only existing neighbors.
- Masks are rectangular dense arrays of numeric 0/1 cells, with at most 64 rows and 64 columns. Empty frames are allowed where no in-bounds seed is required. Stencils are nonempty lists of distinct integer [rowOffset,columnOffset] pairs, each coordinate between -16 and 16. Outside-frame samples are zero at every stage.
- Every declared outer field is required and unknown outer fields are rejected. Strings and JSON text have size limits, lists are bounded to 128 entries, and JSON nesting/node counts are bounded. Tighter operation-specific bounds stated above take precedence.
- Numeric outputs must remain finite and within safe-integer magnitude. Original record indexes and cell coordinates are zero-based; stated half-open ranges exclude their end.
Alternative or Complementary methods
Choose a component operation for connected regions and an explicit stencil for local shape tests. Fix connectivity and border policy before comparing masks; convert cell counts to physical area separately when pixel spacing is known.
References
Similar or alternative tools
- Binary Mask Isolated Cell Remover
Remove foreground components containing exactly one cell under the chosen connectivity.
- Binary Mask Explicit Stencil Opening
Apply explicit-stencil erosion followed by dilation within the original finite binary-grid frame.