filt3d通过卷积过滤带遮罩的图像(矩阵),R语言imagefx包,时序图像特征识别

filt3d通过卷积过滤带遮罩的图像(矩阵),R语言imagefx包,时序图像特征识别

# Tue Oct 12 14:25:05 2021 edit
# 字符编码:UTF-8
# R 版本:R 4.1.1 x64 for window 11
# [email protected]
# 个人笔记不负责任,拎了个梨
#.rs.restartR()
require(imagefx)
rm(list = ls());gc()

?   filt3d  #       通过卷积过滤带遮罩的图像(矩阵)
## generate test data
data <- matrix(0,nrow=256,ncol=256)

box.width = 100
box.height = 100
box.mid=c(nrow(data)/2,ncol(data)/2)

## define where the box indices are
box.row.inds <- (box.mid[1]-box.width/2):(box.mid[1]+box.width/2)
box.col.inds <- (box.mid[2]-box.height/2):(box.mid[2]+box.height/2)

## create the box in the data matrix
data[box.row.inds,box.col.inds] = 1

## define the sigma in the low pass Gaussian filter
sig=5

##创建一个低通高斯滤波器
gaus <- build.gaus(nrow(data),ncol(data),sig)
##用高斯滤波掩模对数据矩阵进行滤波
data.lp <- filt3d(data,gaus)

dev.new()
close.screen(all.screens=TRUE)
split.screen(c(1,3))

## set up some grid lines
grid.xs <- 1:nrow(data)
grid.ys <- 1:ncol(data)

screen(1)
image(grid.xs,grid.ys,data,col=gray.colors(200),useRaster=TRUE,main="Data")

screen(2)
image(grid.xs,grid.ys,gaus,col=gray.colors(200),useRaster=TRUE,main="Low Pass Gaussian Mask")

screen(3)
image(grid.xs,grid.ys,data.lp,col=gray.colors(200),useRaster=TRUE,main='Filtered Data')

## close screens
close.screen(all.screens=TRUE)
dev.copy(png, "filt3d通过卷积过滤带遮罩的图像(矩阵)1.png");dev.off()


#ex2 Tue Oct 12 14:28:19 2021 ------------------------------
rm(list=ls());gc()
data <- matrix(0,nrow=256,ncol=256)

box.width = 100
box.height = 100
box.mid=c(nrow(data)/2,ncol(data)/2)

## define where the box indices are
box.row.inds <- (box.mid[1]-box.width/2):(box.mid[1]+box.width/2)
box.col.inds <- (box.mid[2]-box.height/2):(box.mid[2]+box.height/2)

## create the box in the data matrix
data[box.row.inds,box.col.inds] = 1

## find the middle of the data matrix
mid <- c(nrow(data)/2,ncol(data)/2)

## create a 5-point Laplacian high pass filter
lap <- matrix(0,nrow=nrow(data),ncol=ncol(data))
lap[(mid[1]-1):(mid[1]+1),mid[2]] = c(1,-4,1)
lap[mid[1],(mid[2]-1):(mid[2]+1)] = c(1,-4,1)

## perform  high pass filter on the data using the Laplacian mask
data.hp <- filt3d(data,lap)


## PLOTTING EG2 ##

## set up some grid lines
grid.xs <- 1:nrow(data)
grid.ys <- 1:ncol(data)

dev.off()
close.screen(all.screens=TRUE)
split.screen(c(1,3))

screen(1)
image(grid.xs,grid.ys,data,col=gray.colors(200),useRaster=TRUE,main="Data")

screen(2)
image(grid.xs,grid.ys,lap,col=gray.colors(200),useRaster=TRUE,main="High Pass Laplacian Mask")

screen(3)
image(grid.xs,grid.ys,data.hp,col=gray.colors(200),useRaster=TRUE,main='Filtered Data')
dev.copy(png, "filt3d通过卷积过滤带遮罩的图像(矩阵)2.png");dev.off()

## close screens
close.screen(all.screens=TRUE)
#ex3 Tue Oct 12 14:29:50 2021 ------------------------------

rm(list=ls());gc()## generate test data
data <- matrix(0,nrow=256,ncol=256)

box.width = 100
box.height = 100
box.mid=c(nrow(data)/2,ncol(data)/2)

## define where the box indices are
box.row.inds <- (box.mid[1]-box.width/2):(box.mid[1]+box.width/2)
box.col.inds <- (box.mid[2]-box.height/2):(box.mid[2]+box.height/2)

## create the box in the data matrix
data[box.row.inds,box.col.inds] = 1

## create a delta function at some (x,y) location
delta.x = 80
delta.y = 180
delta <- matrix(0,nrow=nrow(data),ncol=ncol(data))
delta[delta.x,delta.y] = 1

## perform the shift transform filter
data.shift <- filt3d(data,delta)


## PLOTTING EG3 ##

## set up some grid lines
grid.xs <- 1:nrow(data)
grid.ys <- 1:ncol(data)

dev.off()
close.screen(all.screens=TRUE)
split.screen(c(1,3))

screen(1)
image(grid.xs,grid.ys,data,col=gray.colors(200),useRaster=TRUE,main="Data")

screen(2)
image(grid.xs,grid.ys,delta,col=gray.colors(200),useRaster=TRUE,main="Shift Delta Mask")

screen(3)
image(grid.xs,grid.ys,data.shift,col=gray.colors(200),useRaster=TRUE,main='Filtered Data')

## close screens
close.screen(all.screens=TRUE)
dev.copy(png, "filt3d通过卷积过滤带遮罩的图像(矩阵)3.png");dev.off()

# Tue Oct 12 14:32:02 2021 ---


filt3d通过卷积过滤带遮罩的图像(矩阵)1.png
filt3d通过卷积过滤带遮罩的图像(矩阵)2.png
filt3d通过卷积过滤带遮罩的图像(矩阵)3.png

你可能感兴趣的:(filt3d通过卷积过滤带遮罩的图像(矩阵),R语言imagefx包,时序图像特征识别)