Contents

floodFill(from:newColor:connectivity:)

Applies an in-place flood-fill operation to the interleaved 4-channel, unsigned16-bit-per-pixel image.

Declaration

func floodFill(from seed: CGPoint, newColor: Pixel_ARGB_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 interleaved 4-channel, 16-bit-per-pixel pixel buffer and uses the image’s center pixel as the seed.

// `pixelBuffer` is a `vImage.PixelBuffer<vImage.Interleaved16Ux4>`.

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]

See Also

Related Documentation

Applying a flood fill to an image