標籤:die 誤差 lob return 1.0 html const ons class
高光譜映像重構評價指標及其Python實現
高光譜映像重構的評價指標通常有三項。其中部分指標從普通映像變化而來,部分指標只有高光譜映像專屬。本文擬從以下兩個角度介紹高光譜映像評價指標,並列出基於Python語言的skimage庫的對應實現方法。
1)從普通映像重構評價指標到高光譜映像重構評價指標
2)從普通映像重構評價指標代碼到高光譜映像重構評價指標代碼
一、MSE
MSE計算兩組資料的均方誤差,是最常用的評價相似性的準則,包括但不限於映像、訊號。
Skimage庫中對應的函數原型:
skimage.measure.compare_mse
(im1, im2)
Parameters: |
im1, im2 : ndarray Image. Any dimensionality. |
Returns: |
mse : float The mean-squared error (MSE) metric. |
想要測度其他距離,參考compare_nrmse函數
http://scikit-image.org/docs/stable/api/skimage.measure.html#compare-nrmse
二、PSNR與MPSNR1. PSNR
PSNR全稱是Compute the peak signal to noise ratio。用於計算原始映像與重構映像之間的峰值信噪比。在映像超解析度等任務中尤為常用,如同錯誤率之於分類任務,PSNR是映像重構任務事實上的基準評價準則。
skimage.measure.compare_psnr(im_true, im_test, data_range=None, dynamic_range =None )
Parameters: |
im_true : ndarray Ground-truth image. im_test : ndarray Test image. data_range : int The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type. |
Returns: |
psnr : float The PSNR metric. |
2. MPSNR
MPSNR用於計算兩幅高光譜映像之間的平均峰值信噪比。MPSNR計算方法很簡單,只需要分別計算不同波段的PSNR,取均值就可以了。
1 def mpsnr(x_true, x_pred): 2 """ 3 4 :param x_true: 高光譜映像:格式:(H, W, C) 5 :param x_pred: 高光譜映像:格式:(H, W, C) 6 :return: 計算原始高光譜資料與重構高光譜資料的均方誤差 7 References 8 ---------- 9 .. [1] https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio10 """11 n_bands = x_true.shape[2]12 p = [compare_psnr(x_true[:, :, k], x_pred[:, :, k], dynamic_range=np.max(x_true[:, :, k])) for k in range(n_bands)]13 return np.mean(p)
三、SSIM與MSSIM1. SSIM用於計算兩幅映像之間的平均結構相似性。
skimage.measure.compare_ssim
(X, Y, win_size=None, gradient=False, data_range=None, multichannel=False, gaussian_weights=False, full=False, dynamic_range=None, **kwargs)
Parameters: |
X, Y : ndarray Image. Any dimensionality. win_size : int or None The side-length of the sliding window used in comparison. Must be an odd value. If gaussian_weights is True, this is ignored and the window size will depend on sigma. gradient : bool, optional If True, also return the gradient. data_range : int, optional The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type. multichannel : bool, optional If True, treat the last dimension of the array as channels. Similarity calculations are done independently for each channel then averaged. gaussian_weights : bool, optional If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5. full : bool, optional If True, return the full structural similarity image instead of the mean value. |
Returns: |
mssim : float The mean structural similarity over the image. grad : ndarray The gradient of the structural similarity index between X and Y [R327]. This is only returned if gradient is set to True. S : ndarray The full SSIM image. This is only returned if full is set to True. |
Other Parameters: |
|
use_sample_covariance : bool if True, normalize covariances by N-1 rather than, N where N is the number of pixels within the sliding window. K1 : float algorithm parameter, K1 (small constant, see [R326]) K2 : float algorithm parameter, K2 (small constant, see [R326]) sigma : float sigma for the Gaussian when gaussian_weights is True. |
2. MSSIM
MSSIM用於計算兩幅高光譜映像之間的平均結構相似性。MSSIM計算方法很簡單,只需要分別計算不同波段的SSIM指數,取均值就可以了。
1 def mssim(x_true,x_pred):2 """3 :param x_true: 高光譜映像:格式:(H, W, C)4 :param x_pred: 高光譜映像:格式:(H, W, C)5 :return: 計算原始高光譜資料與重構高光譜資料的結構相似性6 """7 SSIM = compare_ssim(X=x_true, Y=x_pred, multichannel=True)8 return SSIM
四、SAM
SAM這個概念只存在於多/高光譜映像,普通映像沒有這個概念。SAM又稱光譜角相似性,用於度量原始高光譜資料與重構高光譜資料之間的光譜相似性。
1 def sam(x_true, x_pred): 2 """ 3 :param x_true: 高光譜映像:格式:(H, W, C) 4 :param x_pred: 高光譜映像:格式:(H, W, C) 5 :return: 計算原始高光譜資料與重構高光譜資料的光譜角相似性 6 """ 7 assert x_true.ndim ==3 and x_true.shape == x_pred.shape 8 sam_rad = np.zeros(x_pred.shape[0, 1]) 9 for x in range(x_true.shape[0]):10 for y in range(x_true.shape[1]):11 tmp_pred = x_pred[x, y].ravel()12 tmp_true = x_true[x, y].ravel()13 sam_rad[x, y] = np.arccos(tmp_pred / (norm(tmp_pred) * tmp_true / norm(tmp_true)))14 sam_deg = sam_rad.mean() * 180 / np.pi15 return sam_deg
五、相關資料0. 文中用到的代碼
https://github.com/JiJingYu/tensorflow-exercise/tree/master/HSI_evaluate
1. 文中提到的函數的文檔
http://scikit-image.org/docs/stable/api/skimage.measure.html#compare-mse
2. PSNR維基百科連結https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio3. SSIM參考文獻
[R326] Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf , DOI:10.1.1.11.2477
[R327] Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613-621. http://arxiv.org/abs/0901.0065 , DOI:10.1007/s10043-009-0119-z
高光譜映像重構常用評價指標及其Python實現