計算 img1 和 img2 之間的 SSIM 索引。
用法
tf.image.ssim(
img1, img2, max_val, filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03
)
參數
-
img1
第一個圖像批次。形狀為[batch, height, width, channels]
的 4-D 張量,隻有正像素值。 -
img2
第二批圖像。形狀為[batch, height, width, channels]
的 4-D 張量,隻有正像素值。 -
max_val
圖像的動態範圍(即最大值和最小值之間的差異)。 -
filter_size
默認值 11(高斯濾波器的大小)。 -
filter_sigma
默認值 1.5(高斯濾波器的寬度)。 -
k1
默認值 0.01 -
k2
默認值 0.03(對於較低的值,SSIM 對 K2 的敏感性較低,因此如果我們取 0 < K2 < 0.4 範圍內的值會更好)。
返回
- 包含批量每個圖像的 SSIM 值的張量。返回的 SSIM 值在 (-1, 1] 範圍內,當像素值為非負時。返回一個形狀為:broadcast(img1.shape[:-3], img2.shape[:-3]) 的張量。
此函數基於以下標準 SSIM 實現:Wang, Z.、Bovik, A. C.、Sheikh, H. R. 和 Simoncelli, E. P. (2004)。圖像質量評估:從錯誤可見性到結構相似性。 IEEE 圖像處理交易。
注意:真正的 SSIM 僅在灰度上定義。此函數不執行任何色彩空間變換。 (如果輸入已經是 YUV,那麽它將計算 YUV SSIM 平均值。)
細節:
- 使用寬度為 1.5 的 11x11 高斯濾波器。
- k1 = 0.01,k2 = 0.03,如原始論文中所述。
由於過濾器大小,圖像大小必須至少為 11x11。
例子:
# Read images (of size 255 x 255) from file.
im1 = tf.image.decode_image(tf.io.read_file('path/to/im1.png'))
im2 = tf.image.decode_image(tf.io.read_file('path/to/im2.png'))
tf.shape(im1) # `img1.png` has 3 channels; shape is `(255, 255, 3)`
tf.shape(im2) # `img2.png` has 3 channels; shape is `(255, 255, 3)`
# Add an outer batch for each image.
im1 = tf.expand_dims(im1, axis=0)
im2 = tf.expand_dims(im2, axis=0)
# Compute SSIM over tf.uint8 Tensors.
ssim1 = tf.image.ssim(im1, im2, max_val=255, filter_size=11,
filter_sigma=1.5, k1=0.01, k2=0.03)
# Compute SSIM over tf.float32 Tensors.
im1 = tf.image.convert_image_dtype(im1, tf.float32)
im2 = tf.image.convert_image_dtype(im2, tf.float32)
ssim2 = tf.image.ssim(im1, im2, max_val=1.0, filter_size=11,
filter_sigma=1.5, k1=0.01, k2=0.03)
# ssim1 and ssim2 both have type tf.float32 and are almost equal.
相關用法
- Python tf.image.stateless_random_flip_up_down用法及代碼示例
- Python tf.image.stateless_random_jpeg_quality用法及代碼示例
- Python tf.image.stateless_random_hue用法及代碼示例
- Python tf.image.stateless_random_crop用法及代碼示例
- Python tf.image.stateless_random_contrast用法及代碼示例
- Python tf.image.stateless_random_saturation用法及代碼示例
- Python tf.image.sobel_edges用法及代碼示例
- Python tf.image.stateless_random_flip_left_right用法及代碼示例
- Python tf.image.sample_distorted_bounding_box用法及代碼示例
- Python tf.image.stateless_random_brightness用法及代碼示例
- Python tf.image.stateless_sample_distorted_bounding_box用法及代碼示例
- Python tf.image.random_brightness用法及代碼示例
- Python tf.image.pad_to_bounding_box用法及代碼示例
- Python tf.image.adjust_hue用法及代碼示例
- Python tf.image.random_contrast用法及代碼示例
- Python tf.image.rot90用法及代碼示例
- Python tf.image.random_hue用法及代碼示例
- Python tf.image.flip_left_right用法及代碼示例
- Python tf.image.convert_image_dtype用法及代碼示例
- Python tf.image.random_saturation用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.image.ssim。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。