#
# image detection (2d)
#
a <- matrix(rep(0,100*100),nrow=100)
a[35:70,35:70]<-1
a <- a + matrix(rnorm(100*100,0,2),nrow=100)
k <- kza(a,q=15)
x <- seq(1,100)
y <- x
op <- par(bg = "white")
#noise
persp(x, y, a, zlab="z", zlim=c(-4,6), ticktype="detailed", theta = 30, phi = 30, col = "lightblue")
#kza filtered
persp(x, y, k, zlab="z", zlim=c(0,2), ticktype="detailed", theta = 30, phi = 30, col = "lightblue")
par(mfrow=c(1,2))
image(a,col=gray(seq(0,1,1/255)))
image(k,col=gray(seq(0,1,1/255)))
#
#wedge example (3d)
#
m<-array(data=0, dim=c(50,50,50))
for (i in 15:35) {
m[i:35,15:35,i] <- 1
}
m<-m+rnorm(n = 50*50*50, sd = 5)
a<-kz(m,7,3)
b<-kza(m,kz=a,q=7,k=3)
#movie of noisy 3d object
for(i in 1:50) {
image(matrix(m[,,i],50,50),col=gray(seq(0,min(max(m[,,i]),1),1/255)))
}
#movie of kza filtered
for(i in 1:50) {
image(matrix(b[,,i],50,50),col=gray(seq(0,min(max(b[,,i]),1),1/255)))
}
#
# this is an example of detection of a break point in a time series
# seasonal data
yrs <- 20
t <- seq(0,yrs,length=yrs*365)
q <- 365
#noise
e <- rnorm(n = length(t),0,1)
trend <- seq(0,-1,length=length(t))
#signal
bkpt <- 3452
brk <- c(rep(0,bkpt),rep(0.5,length(t)-bkpt))
signal <- trend + brk
# y = seasonal + trend + break point + noise
y <- sin(2*pi*t) + signal + e
k.kz <- kz(y,q)
# kza reconstruction of the signal
k.kza <- kza(y,q,m=10)
par(mfrow=c(1,2))
plot(y,type="l", ylim=c(-3,3))
plot(signal,type="l",ylim=c(-3,3),
main="Signal and KZA Reconstruction")
lines(k.kza, col=4)
Run the code above in your browser using DataLab