my.border: 2D area's border

Description Usage Arguments Examples

Description

These function is for 2D 0/1 image matrix and returns its border

Usage

1
my.border(x, r = 1)

Arguments

x

is a 0/1 matrix.

r

is a positive real value of width to measure circumference.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(igraph)
n <- 2^8
x <- y <- 1:n
xy <- as.matrix(expand.grid(x,y))
xy.val <- rep(0,length(xy[,1]))
n.circle <- 30
ctr <- matrix(sample(50:200,replace=TRUE,n.circle*2),ncol=2)
r <- sample(1:40,replace=TRUE,n.circle)

for(i in 1:n.circle){
	tmp.x <- xy[,1] - ctr[i,1]
	tmp.y <- xy[,2] - ctr[i,2]
	s <- which(tmp.x^2+tmp.y^2 < r[i]^2)
	xy.val[s] <- 1
}
xy.mat <- matrix(xy.val,ncol=n)
out <- my.border(xy.mat)
plot(out$border,type="l")

ryamada22/Ronlyryamada documentation built on May 28, 2019, 10:43 a.m.