tf.image.resize_bilinear 图像缩放,双线性插值-图像中心对齐

http://www.cnblogs.com/yssongest/p/5303151.html 

 双线性插值算法及需要注意事项 

 

input = tf.placeholder(tf.float32, shape=(1,2, 2,1))
image = np.ndarray(shape=(1,2,2,1),dtype='float32')
image[0,0,1,0] = 1
image[0,1,0,0] = 2
image[0,1,1,0] = 3
resize =  tf.image.resize_bilinear(input, [4, 4],align_corners=False)
out = sess.run(resize ,feed_dict={input:image})

结果:
[[[[ 0. ],
         [ 0.5],
         [ 1. ],
         [ 1. ]],

        [[ 1. ],
         [ 1.5],
         [ 2. ],
         [ 2. ]],

        [[ 2. ],
         [ 2.5],
         [ 3. ],
         [ 3. ]],

        [[ 2. ],
         [ 2.5],
         [ 3. ],
         [ 3. ]]]]

align_corners=True 结果:
[[[[ 0.        ]
   [ 0.33333334]
   [ 0.66666669]
   [ 1.        ]]

  [[ 0.66666669]
   [ 1.        ]
   [ 1.33333337]
   [ 1.66666675]]

  [[ 1.33333337]
   [ 1.66666663]
   [ 2.        ]
   [ 2.33333349]]

  [[ 2.        ]
   [ 2.33333325]
   [ 2.66666675]
   [ 3.        ]]]]

tf的resize_bilinear并未中心对齐,坐标计算方式为

align_corners=False:

srcX=dstX* (srcWidth/dstWidth) ,
srcY = dstY * (srcHeight/dstHeight)

align_corners=True:

srcX=dstX* (srcWidth-1/dstWidth-1) ,
srcY = dstY * (srcHeight-1/dstHeight-1)

posted @ 2017-08-21 14:35  mlj318  阅读(9296)  评论(0编辑  收藏  举报