Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

floodFill

Region filling


Description

Fill regions in images.

Usage

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

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

Image processing and analysis toolbox for R

v4.32.0
LGPL
Authors
Andrzej Oleś, Gregoire Pau, Mike Smith, Oleg Sklyar, Wolfgang Huber, with contributions from Joseph Barry and Philip A. Marais
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.