Hello!
I am trying to calculate the SSIM score between two images using the following code:
import torch
import torchvision.transforms.functional as F
from PIL import Image
from pytorch_msssim import ssim
content_img_path = "/home/input/Version2/Contents/img1.jpg"
stylized_img_path = "/home/input/Version2/Styles/img2.jpg"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
content_img = Image.open(content_img_path).convert("RGB")
stylized_img = Image.open(stylized_img_path).convert("RGB")
stylized_img = stylized_img.resize(content_img.size, Image.BILINEAR)
content_tensor = F.to_tensor(content_img).unsqueeze(0).to(device)
stylized_tensor = F.to_tensor(stylized_img).unsqueeze(0).to(device)
ssim_value = ssim(content_tensor, stylized_tensor).item()
print("SSIM score:", ssim_value)
If I take the same image then I get a score of 1.0 which is expected. However, even for two completely different images, I get a very high value around 0.98-0.99.
Can someone please let me know whether I am doing it right or if there is any issue with the code?