• 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)

  • 相关阅读:
    nginx一键安装脚本
    nginx动静分离之后,设置默认主页
    日志备份
    cc高防主机部署
    原型和原型链
    Git&Github分支
    Git&Github基础
    传输层协议TCP&UDP
    本地库与远程库交互
    SVG
  • 原文地址:https://www.cnblogs.com/mlj318/p/7404241.html
Copyright © 2020-2023  润新知