({{, (RefLink[DeleteBorderComponents, paclet:ref/DeleteBorderComponents])[image] 
replaces connected components adjacent to the border in a binary image image with background pixels.}, {, (RefLink[DeleteBorderComponents, paclet:ref/DeleteBorderComponents])[m]
replaces components adjacent to the border in a label matrix m with 0.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[DeleteBorderComponents, paclet:ref/DeleteBorderComponents]) works with arbitrary 2D and 3D images or label matrices.

(RefLink[DeleteBorderComponents, paclet:ref/DeleteBorderComponents]) takes a (RefLink[CornerNeighbors, paclet:ref/CornerNeighbors]) option. The default setting is (RefLink[CornerNeighbors, paclet:ref/CornerNeighbors])->(RefLink[True, paclet:ref/True]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Deleting components connected to the image border in a binary image:

DeleteBorderComponents[]

Deleting components connected to the border of a 3D image:

DeleteBorderComponents[]

OpenersExampleSection1(Spacer1)Scope  (1)

Deleting the border component from a label matrix:

DeleteBorderComponents[ (({{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 2}}))]//MatrixForm

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)CornerNeighbors  (1)

By default, 8-connectivity is assumed:

DeleteBorderComponents[]

Assume 4-connectivity for computing the components:

DeleteBorderComponents[,CornerNeighbors->False]

OpenersExampleSection3(Spacer1)Applications  (1)

Create a texture image by periodically padding a single pattern:

pattern=;

ii=ImageCrop[pattern,{100,80},Padding->"Periodic"]

Remove patterns that are adjacent to the border and therefore are incomplete:

DeleteBorderComponents[ii]

OpenersExampleSection4(Spacer1)Properties & Relations  (2)

When deleting border components from a label matrix, components are not relabeled:

DeleteBorderComponents[ (({{0, 0, 0, 0, 1}, {0, 2, 2, 0, 0}, {0, 0, 0, 0, 3}, {0, 4, 4, 0, 0}, {0, 0, 0, 0, 5}}))]//MatrixForm

It is also possible to obtain the same effect by masking the border, then using (RefLink[GeodesicDilation, paclet:ref/GeodesicDilation]):

i=;
{w,h}=ImageDimensions[i];
a=ImageMultiply[ImagePad[ConstantImage[Black,{w,h}-2],1,White],i]
i-GeodesicDilation[a,i]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DeleteSmallComponents, paclet:ref/DeleteSmallComponents])  ▪  (RefLink[ComponentMeasurements, paclet:ref/ComponentMeasurements])  ▪  (RefLink[MorphologicalComponents, paclet:ref/MorphologicalComponents])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Segmentation Analysis, paclet:guide/SegmentationAnalysis])}, {▪(RefLinkPlain[Mathematical Morphology, paclet:guide/MathematicalMorphology])}})}})