高光譜圖像重構經常使用評價指標及其Python實現

高光譜圖像重構評價指標及其Python實現html

高光譜圖像重構的評價指標一般有三項。其中部分指標從普通圖像變化而來,部分指標只有高光譜圖像獨有。本文擬從如下兩個角度介紹高光譜圖像評價指標,並列出基於Python語言的skimage庫的對應實現方法。git

1)從普通圖像重構評價指標到高光譜圖像重構評價指標github

2)從普通圖像重構評價指標代碼到高光譜圖像重構評價指標代碼api

1、MSE

MSE計算兩組數據的均方偏差,是最經常使用的評價類似度的準則,包括但不限於圖像、信號。ide

Skimage庫中對應的函數原型:函數

skimage.measure.compare_mse(im1, im2)this

Parameters:lua

im1, im2 : ndarrayspa

Image. Any dimensionality.code

Returns:

mse : float

The mean-squared error (MSE) metric.

想要測度其餘距離,參考compare_nrmse函數

http://scikit-image.org/docs/stable/api/skimage.measure.html#compare-nrmse

2、PSNR與MPSNR

1. 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_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)

 

3、SSIM與MSSIM

1. 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

 

4、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.pi
15     return sam_deg

 

5、相關資料

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_ratio

3. 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

相關文章
相關標籤/搜索