【问题标题】:Pixel values difference between Tensorflow and skimageTensorflow 和 skimage 之间的像素值差异
【发布时间】:2021-05-24 09:30:46
【问题描述】:

如果我使用skimage.io.imread(image)tf.image.decode_image(image) 打开图像,为什么像素值之间存在差异?

例如:

import skimage.io
original_img = skimage.io.imread("test.jpg")
print(original_img.shape)
print(np.amax(original_img))
print(original_img)

输出是:

(110, 150, 3)
255
array([[[ 29,  65, 117],
        [ 45,  43,  90],
        [ 78,  39,  68],
        ...,
        [ 30,  46,  95],
        [ 30,  43,  96],
        [ 31,  44,  97]],

       [[ 41,  54,  89],
        [ 95,  89, 123],
        [ 57,  39,  65],
        ...,
        [ 32,  46,  91],
        [ 32,  46,  95],
        [ 32,  45,  97]],

       [[ 62,  49,  69],
        [ 84,  76,  97],
        [ 68,  70,  95],
        ...,
        [ 18,  30,  70],
        [ 35,  47,  95],
        [ 34,  47,  99]],

       ...,

       [[136, 124,  22],
        [144, 136,  53],
        [134, 123,  44],
        ...,
        [ 16,  74,  16],
        [ 39,  89,  52],
        [ 53, 108,  69]],

       [[161, 125,   5],
        [149, 129,  42],
        [129, 116,  48],
        ...,
        [ 67, 119,  73],
        [ 39,  80,  48],
        [ 33,  69,  41]],

       [[196, 127,   6],
        [160, 111,  32],
        [141, 108,  55],
        ...,
        [ 26,  56,  32],
        [  8,  29,  10],
        [ 12,  24,  12]]], dtype=uint8)

如果我用Tensorflow打开同一张图片:

import tensorflow as tf

original_img = tf.image.decode_image(tf.io.read_file("test.jpg"))
print(np.amax(original_img))
print(original_img)

输出是:

255
<tf.Tensor: shape=(110, 150, 3), dtype=uint8, numpy=
array([[[ 44,  57, 101],
        [ 40,  42,  80],
        [ 65,  41,  65],
        ...,
        [ 25,  42,  88],
        [ 33,  49, 100],
        [ 25,  41,  92]],

       [[ 47,  53,  89],
        [ 96,  95, 127],
        [ 60,  44,  70],
        ...,
        [ 29,  43,  88],
        [ 40,  54, 103],
        [ 19,  35,  84]],

       [[ 59,  54,  74],
        [ 72,  69,  90],
        [ 70,  70,  96],
        ...,
        [ 23,  35,  77],
        [ 16,  29,  74],
        [ 50,  64, 111]],

       ...,

       [[145, 116,  24],
        [161, 131,  43],
        [141, 113,  30],
        ...,
        [ 19,  67,  19],
        [ 49,  95,  58],
        [ 53,  97,  64]],

       [[164, 119,  16],
        [166, 123,  28],
        [143, 108,  27],
        ...,
        [ 73, 119,  80],
        [ 29,  68,  37],
        [ 39,  75,  47]],

       [[182, 128,  20],
        [160, 112,  14],
        [149, 112,  32],
        ...,
        [ 11,  57,  21],
        [  7,  44,  13],
        [  0,  14,   0]]], dtype=uint8)>

我还注意到,如果我用tensorflow打开一个图像,对这个图像做一些改变,把图像保存在磁盘上,然后用tf.image.decode_image(image)再次打开它,像素值又不一样了,但这一次,没那么多。

【问题讨论】:

    标签: python tensorflow tensorflow2.0 scikit-image


    【解决方案1】:

    这是由于用于解压缩的算法。默认情况下,使用系统特定的方法。 tf.image.decode_image() 不提供任何更改方法的可能性。

    tf.image.decode_jpeg() 中有dct_method 参数可以用来改变解压的方法。目前可以设置两个有效值:INTEGER_FASTINTEGER_ACCURATE

    如果您以以下方式打开图像,您应该会得到与skimage.io.imread(image) 相同的输出:

    original_img = tf.image.decode_jpeg(tf.io.read_file("test.jpg"),dct_method="INTEGER_ACCURATE")
    

    【讨论】:

      猜你喜欢
      • 2013-07-16
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 2020-11-04
      • 1970-01-01
      相关资源
      最近更新 更多