标签:die 误差 lob return 1.0 html const ons class
高光谱图像重构评价指标及其Python实现
高光谱图像重构的评价指标通常有三项。其中部分指标从普通图像变化而来,部分指标只有高光谱图像独有。本文拟从以下两个角度介绍高光谱图像评价指标,并列出基于Python语言的skimage库的对应实现方法。
1)从普通图像重构评价指标到高光谱图像重构评价指标
2)从普通图像重构评价指标代码到高光谱图像重构评价指标代码
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全称是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. |
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_ratio 10 """ 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)
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. |
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又称光谱角相似度,用于度量原始高光谱数据与重构高光谱数据之间的光谱相似度。
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.pi 15 return sam_deg
https://github.com/JiJingYu/tensorflow-exercise/tree/master/HSI_evaluate
http://scikit-image.org/docs/stable/api/skimage.measure.html#compare-mse
[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
标签:die 误差 lob return 1.0 html const ons class
原文地址:http://www.cnblogs.com/nwpuxuezha/p/6659153.html