!pip install scikit-image
from skimage import io, img_as_float from skimage.metrics import structural_similarity as ssim import matplotlib.pyplot as plt # 加载图像 img1 = io.imread('adjusted_img1.jpg', as_gray=False) img2 = io.imread('adjusted_img2.jpg', as_gray=False) # 输出图像尺寸以便检查 print("Image 1 size:", img1.shape) print("Image 2 size:", img2.shape) # 确保图像为浮点类型 img1 = img_as_float(img1) img2 = img_as_float(img2) # 设置合适的SSIM计算窗口大小 smallest_side = min(img1.shape[0], img1.shape[1], img2.shape[0], img2.shape[1]) win_size = min(7, smallest_side) # 确保窗口大小不超过最小边长 if win_size % 2 == 0 and win_size > 1: # 确保win_size是奇数,同时至少为1 win_size -= 1 # 检查窗口大小 print("Using win_size:", win_size) # 计算SSIM if win_size >= 1: # 确保窗口大小至少为1 ssim_index, ssim_map = ssim(img1, img2, win_size=win_size, full=True, channel_axis=-1) print("SSIM:", ssim_index) # 可视化SSIM图 plt.imshow(ssim_map, cmap=plt.cm.gray) plt.colorbar() plt.title('SSIM Map') plt.show() else: print("Image too small for SSIM calculation with default settings.")
预处理见PNSR
标签:win,SSIM,shape,colab,img2,img1,比较,size From: https://www.cnblogs.com/Anonytt/p/18278341