本文整理汇总了Python中skimage.measure.compare_psnr方法的典型用法代码示例。如果您正苦于以下问题:Python measure.compare_psnr方法的具体用法?Python measure.compare_psnr怎么用?Python measure.compare_psnr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.measure
的用法示例。
在下文中一共展示了measure.compare_psnr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def compare(inp_img, out_img, calc_ssim=True, calc_msssim=True, calc_psnr=True):
inp_img = _read_if_not_array(inp_img)
out_img = _read_if_not_array(out_img)
assert inp_img.shape == out_img.shape
def get_ssim():
return compare_ssim(inp_img, out_img, multichannel=True, gaussian_weights=True, sigma=1.5)
def get_msssim():
return MultiScaleSSIM(make_batched(inp_img), make_batched(out_img))
def get_psnr():
return compare_psnr(inp_img, out_img)
def _run_if(cond, fn):
return fn() if cond else None
return _run_if(calc_ssim, get_ssim), _run_if(calc_msssim, get_msssim), _run_if(calc_psnr, get_psnr)
示例2: slice_process
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def slice_process(x1, x2, y):
if len(x1.shape) == 3: x1 = x1[0,:,:]
if len(x2.shape) == 3: x2 = x2[0,:,:]
if len(y.shape) == 3: y = y[0,:,:]
# a scaled and shifted version of pred and bilinear
x1 = 2*x1 + 100
x2 = 2*x2 + 100
# normalize/scale images
(y_norm1, x1_norm) = norm_minmse(y, x1)
(y_norm2, x2_norm) = norm_minmse(y, x2)
# calulate psnr and ssim of the normalized/scaled images
psnr1 = compare_psnr(*(y_norm1, x1_norm), data_range = 1.)
psnr2 = compare_psnr(*(y_norm2, x2_norm), data_range = 1.)
ssim1 = compare_ssim(*(y_norm1, x1_norm), data_range = 1.)
ssim2 = compare_ssim(*(y_norm2, x2_norm), data_range = 1.)
return psnr1, ssim1, psnr2, ssim2, y_norm1, x1_norm, y_norm2, x2_norm
示例3: compute_psnr_and_ssim
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def compute_psnr_and_ssim(image1, image2, border_size=0):
"""
Computes PSNR and SSIM index from 2 images.
We round it and clip to 0 - 255. Then shave 'scale' pixels from each border.
"""
if len(image1.shape) == 2:
image1 = image1.reshape(image1.shape[0], image1.shape[1], 1)
if len(image2.shape) == 2:
image2 = image2.reshape(image2.shape[0], image2.shape[1], 1)
if image1.shape[0] != image2.shape[0] or image1.shape[1] != image2.shape[1] or image1.shape[2] != image2.shape[2]:
return None
image1 = trim_image_as_file(image1)
image2 = trim_image_as_file(image2)
if border_size > 0:
image1 = image1[border_size:-border_size, border_size:-border_size, :]
image2 = image2[border_size:-border_size, border_size:-border_size, :]
psnr = compare_psnr(image1, image2, data_range=255)
ssim = compare_ssim(image1, image2, win_size=11, gaussian_weights=True, multichannel=True, K1=0.01, K2=0.03,
sigma=1.5, data_range=255)
return psnr, ssim
示例4: psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def psnr(gt, pred):
""" Compute Peak Signal to Noise Ratio metric (PSNR) """
return compare_psnr(gt, pred, data_range=gt.max())
示例5: calculate_psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def calculate_psnr(output_img, target_img):
target_tf = torch2numpy(target_img)
output_tf = torch2numpy(output_img)
psnr = 0.0
n = 0.0
for im_idx in range(output_tf.shape[0]):
psnr += compare_psnr(target_tf[im_idx, ...],
output_tf[im_idx, ...],
data_range=255)
n += 1.0
return psnr / n
示例6: get_psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def get_psnr(im1, im2):
return compare_psnr(im1, im2, data_range=255)
示例7: __compare_psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def __compare_psnr(planes):
a, b = planes
if (a == b).all():
# Avoid "Warning: divide by zero encountered in double_scalars" generated
# by skimage.measure.compare_psnr when a and b are exactly the same.
return 100
return skimage_psnr(a, b)
示例8: psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def psnr(im1, im2):
def im2double(im):
min_val, max_val = 0, 255
out = (im.astype(np.float64)-min_val) / (max_val-min_val)
return out
im1 = im2double(im1)
im2 = im2double(im2)
psnr = measure.compare_psnr(im1, im2, data_range=1)
return psnr
示例9: psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def psnr(y_true, y_pred, max_value=2):
psnr_metric = measure.compare_psnr(y_true, y_pred, max_value)
return psnr_metric
示例10: mpsnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def mpsnr(x_true, x_pred):
"""
:param x_true: 高光谱图像:格式:(H, W, C)
:param x_pred: 高光谱图像:格式:(H, W, C)
:return: 计算原始高光谱数据与重构高光谱数据的均方误差
References
----------
.. [1] https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
"""
n_bands = x_true.shape[2]
p = [compare_psnr(x_true[:, :, k], x_pred[:, :, k], dynamic_range=np.max(x_true[:, :, k])) for k in range(n_bands)]
return np.mean(p)
示例11: get_psnr
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def get_psnr(self, img_true, img_gen):
return compare_psnr(img_true.astype(np.float32), img_gen.astype(np.float32))
示例12: PSNR
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def PSNR(self, gt, pred):
#gt = gt.astype(np.float64)
#pred = pred.astype(np.float64)
#mse = np.mean((pred - gt)**2)
#psnr = 10*np.log10(255*255/mse)
#return psnr
return compare_psnr(gt, pred, data_range=255)
示例13: test_bm3d
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def test_bm3d(noise_data):
"""Tests BM3D grayscale image denoising."""
img, noisy_img, noise_std_dev = noise_data
out = pybm3d.bm3d.bm3d(noisy_img, noise_std_dev)
noise_psnr = compare_psnr(img, noisy_img)
out_psnr = compare_psnr(img, out)
assert out_psnr > noise_psnr
示例14: test_bm3d_color
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def test_bm3d_color(color_noise_data):
"""Tests BM3D color image denoising."""
img, noisy_img, noise_std_dev = color_noise_data
out = pybm3d.bm3d.bm3d(noisy_img, noise_std_dev)
noise_psnr = compare_psnr(img, noisy_img)
out_psnr = compare_psnr(img, out)
assert out_psnr > noise_psnr
示例15: calcPSNR
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import compare_psnr [as 别名]
def calcPSNR(self, image1, image2):
image1 *= 255
image2 *= 255
image1[image1>255] = 255
image1[image1<0] = 0
image2[image2>255] = 255
image2[image2<0] = 0
return compare_psnr(image1, image2, data_range=255)