floodFill: Region filling

Description Usage Arguments Details Value Author(s) Examples

View source: R/floodFill.R

Description

Fill regions in images.

Usage

1
floodFill(x, pts, col, tolerance=0)

Arguments

x

An Image object or an array.

pts

Coordinates of the start filling points given as either of the following: a vector of the form c(x1, y1, x2, y2, ...), a list of points, a matrix or data frame where rows represent points and columns are the x and y coordinates. For image stacks different points for each frame can be specified by providing them in a list of length matching the number of 'render' frames.

col

Fill color. This argument should be a numeric for Grayscale images and an R color for Color images. Values are recycled such that their length matches the number of points in pts. Can be a list of length matching the number of 'render' frames similarly as pts.

tolerance

Color tolerance used during the fill.

Details

Flood fill is performed using the fast scan line algorithm. Filling starts at pts and grows in connected areas where the absolute difference of the pixels intensities (or colors) remains below tolerance.

Value

An Image object or an array, containing the transformed version of x.

Author(s)

Gregoire Pau, Oleg Sklyar; 2007

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  x = readImage(system.file("images", "shapes.png", package="EBImage"))

  ## fill a shape with 50% shade of gray
  y = floodFill(x, c(67, 146), 0.5)
  display(y)
  
  ## fill with color
  y = toRGB(y)
  y = floodFill(y, c(48, 78), 'orange')	
  display(y)
  
  ## fill multiple shapes with different colors
  y = y[110:512,1:130,]
  points = rbind(c(50, 50), c(100, 50), c(150, 50))
  colors = c("red", "green", "blue")
  y = floodFill(y, points, colors)
  display(y)
  
  ## area fill
  x = readImage(system.file("images", "sample.png", package="EBImage"))
  y = floodFill(x, rbind(c(200, 400), c(200, 325)), 1, tolerance=0.1)
  display(y)
  
  ## application to image stacks
  f = system.file("images", "nuclei.tif", package="EBImage")
  x = readImage(f)[1:250,1:250,]
  x = opening(thresh(x, 12, 12), makeBrush(5, shape='disc'))
  xy = lapply(getFrames(bwlabel(x)), function(x) computeFeatures.moment(x)[,1:2])
  y = floodFill(toRGB(x), xy, c("red", "green", "blue"))
  display(y)

EBImage documentation built on Nov. 17, 2017, 12:34 p.m.