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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM