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)

转载于:https://www.cnblogs.com/mlj318/p/7404241.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值