calc.blob.stats从Blob区域计算颜色和空间统计信息,R语言imagefx包,时序图像特征识别
# Wed Sep 15 16:27:52 2021 -
# 字符编码:UTF-8
# R 版本:R x64 4.1.1 for window 11
# cgh163email@163.com
# 个人笔记不负责任,拎了个梨🍐🍈
#.rs.restartR()
require(imagefx)
rm(list = ls());gc()
? calc.blob.stats # 从Blob区域计算颜色和空间统计信息
img <- build.gaus(100,100,sig.x=2,sig.y=10,x.mid=80,y.mid=60)
image(img)
img.max <- which(img==max(img),arr.ind=TRUE)
img.max |> image()
sig=5
lp.filt <- build.gaus(nrow(img),ncol(img),sig.x=sig)
win.size=0.05
blob <- blob.extract(img=img, blob.point=img.max,win.size=win.size,gaus=lp.filt)
blob.stats <- calc.blob.stats(img, blob$xy.coords)
print(blob.stats)
dev.copy(png, "calc.blob.stats从Blob区域计算颜色和空间统计信息1.png");dev.off()
#eg2 Wed Sep 15 16:31:12 2021 ------------------------------
rm(list=ls());gc()
data(sakurajima)
xleft = 1
xright = 188
ybottom = 1
ytop = 396
cropped <- crop.image(sakurajima, xleft, ybottom, xright, ytop)
img <- cropped$img.crop
## separate the image into red, green, and blue images
r.img <- img[,,1]
g.img <- img[,,2]
b.img <- img[,,3]
dev.off();par(mfrow=c(2,2))
image(r.img)
image(g.img)
image(b.img)
dev.copy(png, "calc.blob.stats从Blob区域计算颜色和空间统计信息2.png");dev.off()
##除去平均数
r.img <- r.img-mean(r.img)
g.img <- g.img-mean(g.img)
b.img <- b.img-mean(b.img)
##计算平面趋势。。。
r.img.trend <- fit3d(r.img)
g.img.trend <- fit3d(g.img)
b.img.trend <- fit3d(b.img)
dev.off();par(mfrow=c(3,1))
image(r.img.trend)
image(g.img.trend)
image(b.img.trend)
dev.copy(png, "calc.blob.stats从Blob区域计算颜色和空间统计信息3.png");dev.off()
##消除趋势
r.img.dtrend <- r.img-r.img.trend
g.img.dtrend <- g.img-g.img.trend
b.img.dtrend <- b.img-b.img.trend
# 设置一些过滤罩
# 为LP高斯滤波器定义一个sigma
gaus.sig=30
##构建高斯滤波器
gaus <- build.gaus(nrow(img),ncol(img),gaus.sig)
##查找每个RGB通道的最大值
blob.r.point <- which(r.img.dtrend==max(r.img.dtrend),arr.ind=TRUE)
blob.g.point <- which(g.img.dtrend==max(g.img.dtrend),arr.ind=TRUE)
blob.b.point <- which(b.img.dtrend==max(b.img.dtrend),arr.ind=TRUE)
##设置要在连接组件算法中使用的窗口大小
win.size = 0.05
## extract the blob xy locations
blob.r <- blob.extract(r.img.dtrend,blob.r.point,win.size,gaus)
blob.g <- blob.extract(g.img.dtrend,blob.r.point,win.size,gaus)
blob.b <- blob.extract(b.img.dtrend,blob.r.point,win.size,gaus)
r.blob.stats <- calc.blob.stats(r.img.dtrend, blob.r$xy.coords)
g.blob.stats <- calc.blob.stats(g.img.dtrend, blob.g$xy.coords)
b.blob.stats <- calc.blob.stats(b.img.dtrend, blob.b$xy.coords)
print(r.blob.stats)
print(g.blob.stats)
print(b.blob.stats)
dev.off();par(mfrow=c(1,3))
plot(r.blob.stats)
plot(g.blob.stats)
plot(b.blob.stats)
dev.copy(png, "calc.blob.stats从Blob区域计算颜色和空间统计信息4.png");dev.off()