VainF / pytorch-msssim

Fast and differentiable MS-SSIM and SSIM for pytorch.
MIT License
1.09k stars 126 forks source link

test ssim_torch and skimage #23

Open ignorant96 opened 4 years ago

ignorant96 commented 4 years ago

Hi, I just test pytorch_msssim.ssim and skimage. When I compute ssim value with these two methods on 2d matrix, I got different results, I want to know what the problem is. Maybe I use ssim in a wrong way? Here are my codes and results.

code: `import torch from skimage.metrics import structural_similarity from pytorch_msssim import ssim

m0 = torch.ones(7, 7, dtype=torch.float) # OR matrix m0[4:7, 0:3] = 0

m_sig = torch.ones(7, 7, dtype=torch.float) m_sig[4:7, 0] = 0

ssim_out = ssim(m0.reshape(1, 1, 7, 7), m_sig.reshape(1, 1, 7, 7)) print('pytorch_ssim_value = ' + str(ssim_out.numpy()))

ssim_value2 = structural_similarity(m_sig.numpy(), m0.numpy()) print('ssim_value = ' + str(ssim_value2))`

results: ytorch_ssim_value = 0.9836789 ssim_value = 0.4858374093651142

VainF commented 4 years ago

The default behavior of structural_similarity is inconsistent with the original paper. Please add these args:

ssim_skimage = structural_similarity(img, img_noise, win_size=11, multichannel=True,
                                    sigma=1.5, data_range=1, use_sample_covariance=False, gaussian_weights=True)