我想计算下两组医学图像的mae,psnr,ssim,你能帮我用Python写一个具体代码吗?
时间: 2024-05-02 08:22:42 浏览: 118
当然可以,以下是一个使用Python计算两组医学图像的MAE、PSNR、SSIM的示例代码:
```python
import skimage.measure as measure
from skimage import io
import numpy as np
# Load images from files
img1 = io.imread('path/to/image1.png', as_gray=True)
img2 = io.imread('path/to/image2.png', as_gray=True)
# Convert images to numpy arrays
img1 = np.array(img1)
img2 = np.array(img2)
# Compute mean absolute error (MAE)
mae = np.sum(np.abs(img1 - img2)) / img1.size
# Compute peak signal-to-noise ratio (PSNR)
max_pixel = 1.0
mse = np.mean((img1 - img2) ** 2)
psnr = 20 * np.log10(max_pixel / np.sqrt(mse))
# Compute structural similarity index (SSIM)
ssim = measure.compare_ssim(img1, img2)
# Print the results
print("MAE: ", mae)
print("PSNR: ", psnr)
print("SSIM: ", ssim)
```
请将 "path/to/image1.png" 和 "path/to/image2.png" 更改为实际的两幅图像的路径。此代码将为您计算MAE、PSNR和SSIM,并在控制台输出结果。
阅读全文