floodFill(from:newColor:connectivity:)
Applies an in-place flood-fill operation to the unsigned 16-bit planar image.
Declaration
func floodFill(from seed: CGPoint, newColor: Pixel_16U, connectivity: vImage.FloodFillConnectivity)Parameters
- seed:
The coordinates that define the position of the seed pixel inside the connected component.
- newColor:
The new pixel value that overwrites the pixels in the connected component.
- connectivity:
An enumeration that specifies which pixels the operation includes as neighbors. Pass Edges to specify a four-connected neighborhood of a pixel that includes the pixels to the left and right, and those above and below. Pass Edgesandcorners to specify an eight-connected neighborhood that includes the four-connected neighborhood and the pixels on the four diagonals.
Discussion
The flood-fill function sets all pixels that are neighboring and identical to the seed pixel to a new color. The operation continues until it reaches the image boundary or until it sets all pixels within the connected component to the new value.
The following code applies a flood fill to an unsigned 16-bit planar pixel buffer and uses the image’s center pixel as the seed.
// `pixelBuffer` is a `vImage.PixelBuffer<vImage.Planar16U>`.
pixelBuffer.floodFill(from: CGPoint(x: pixelBuffer.width / 2,
y: pixelBuffer.height / 2),
newColor: fillColor,
connectivity: .edgesAndCorners)The image below shows the original line-art image on the left, and the flood-filled image on the right:
[Image]