0

I wanted to do some simple image comparisons with R (the reason I am not using python is that the workflow is in R). I tried to search for ms-ssim implementations in packages in R, but did find any except for spatialcompare::msssim. However, as I mentioned in my post yesterday, I figured out that the result of this function might not be correct for my input (could be related to matrix to raster transformation?). Are there any more suggestions for appropriate ms-ssim codes? I actually self-implemented one based on SpatialPack::SSIM because it seems easy to just downsample the image again and again, but am not sure if I am writing it correctly. I'll put it as an answer.

user48867
  • 141
  • 1
  • 9

1 Answers1

0

My demo code for a very simple 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,alpha=1, beta=1, gamma=1, 
                             eps=c(0.01,0.03), L=max(tmp1,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))
}

Is it correct?

user48867
  • 141
  • 1
  • 9