如何解决MS-SSIM 的 R 包?
我想用 R 做一些简单的图像比较(我不使用 python 的原因是工作流在 R 中)。我试图在 R 中的包中搜索 ms-ssim 实现,但确实找到了除 spatialcompare::msssim
之外的任何实现。然而,正如我昨天在 post 中提到的,我发现这个函数的结果可能对我的输入不正确(可能与 matrix
到 raster
的转换有关?)。对于适当的 ms-ssim 代码还有更多建议吗?我实际上是基于 SpatialPack::SSIM
自行实现的,因为一次又一次地对图像进行下采样似乎很容易,但不确定我是否正确编写。我会把它作为答案。
解决方法
我的一个非常简单的 ms-ssim 的演示代码:
calcMSSSIM<-function(Mat1,Mat2){
weight = c(0.0448,0.2856,0.3001,0.2363,0.1333)
level<-5
array<-c()
ssim<-SpatialPack::SSIM(Mat1,Mat2,alpha=1,beta=1,gamma=1,eps=c(0.01,0.03),L=max(tmp1,tmp2))$SSIM
array[1]<-ssim$comps["contrast"]*ssim$comps["structure"]
result<-abs(array[1])^weight[1]
for (i in 2:level) {
tmp1 <- EBImage::resize(tmp1,w=dim(tmp1)[1]/2,filter="none")
tmp2 <- EBImage::resize(tmp2,w=dim(tmp2)[1]/2,filter="none")
ssim <- SpatialPack::SSIM(tmp1,tmp2,tmp2))$SSIM
array[i]<-ssim$comps["contrast"]*ssim$comps["structure"]
result <- result*abs(array[i])^weight[i]
}
lum<-ssim$comps["luminance"]
result<-result*lum^weight[i]
return(list(array,result))
}
正确吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。