floodFill {EBImage} | R Documentation

## Filling matrix data with flood fill algorithm

### Description

Functions to fill regions in images and matrices/arrays and fill holes in indexed objects.

### Usage

      ## S4 method for signature 'array':
      floodFill(x, pt, col, tolerance=1e-3, ...)
      ## S4 method for signature 'IndexedImage':
      fillHull(x, ...)

### Arguments

`x` | An `array`-like object (e.g. `Image`) to be filled. For `fillHull` this must be an instance of `IndexedImage`.
`pt` | An integer of 2 values for `x-y` coordinates of the point where fill starts.
`col` | A value for the fill color, supposedly in the same storage mode as `x`. If `x` is an image `col` will be converted to the corresponding storage mode using the `channel` function, and thus can be a character value specifying the color in X11 mode.
`tolerance` | Color tolerance used during the fill.
`...` | Reserved.

### Details

If no color is specified, the color under the coordinates of `pt` is used (this only has sense if tolerance is not zero). The flood fill is implemented using the fast scan line algorithm. It is assumed that `floodFill` is run either on matrices of single-framed images. If the latter is not the case, only the first frame will be modified!

`fillHull` files holes in objects of `IndexedImage`'s.

### Value

A copy of `x` with the fill applied.

### Author(s)

Gregoire Pau, Oleg Sklyar; 2007

### See Also

`Image, IndexedImage`

### Examples

    if (interactive()) {
      data(imageWithHoles)

      display(x, main="Original image")
      display(floodFill(x,c(5,5),tolerance=0.2))
      display(floodFill(x,c(40,40),tolerance=0.2))

      mask = x
      mask[mask>0.3]=1
      mask[mask<=0.3]=0

      y = floodFill(mask,c(40,40),2)
      class(y) = "IndexedImage"
      display(y, main="Indexed mask with holes")

      y = fillHull(y)
      display(y, main="Indexed mask without holes")

      rgb = channel(normalize(y), "rgb")
      rgb = floodFill(rgb, c(1,1), "red")
      rgb = floodFill(rgb, c(50,50), "blue")
      rgb = floodFill(rgb, c(150,150), "green")
      display(rgb)
    }

[Package EBImage version 2.4.0 Index]