seedfill: Color Fill Algorithm

Description Usage Arguments Details Value See Also Examples

View source: R/seedfill.R

Description

Fills a bounded area within a numeric matrix with a given number (color).

Usage

1
 seedfill(z, x=1, y=1, fcol=0, bcol=1, tol=1e-6)

Arguments

z

a matrix containing an image (double precision values are possible).

x, y

start coordinates of the filled area.

fcol

numeric value of the fill color.

bcol

numeric value of the border value.

tol

numeric value of border color tolerance.

Details

The function implements a basic color fill algorithm for use in image manipulation or cellular automata.

Value

A matrix with the same structure as z.

See Also

neighbours

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# define a matrix
z<-matrix(0, nrow=20, ncol=20)

# draw some lines
z[10,]<-z[,10] <- 1
z[5,] <-z[,5]  <- 3

# plot matrix and filled variants
par(mfrow=c(2, 2))
image(z)
image(seedfill(z))
image(seedfill(z ,x=15, y=15, fcol=1, bcol=3))
image(seedfill(z, x=7, y=7, fcol=3, bcol=1))

Example output

Loading required package: deSolve

simecol documentation built on Oct. 7, 2021, 9:20 a.m.