在tf.image.central_crop函数的Tensorflow文档中:
Remove the outer parts of an image but retain the central region of
the image along each dimension. If we specify central_fraction = 0.5,
this function returns the region marked with "X" in the below diagram.
--------
| |
| XXXX |
| XXXX |
| | where "X" is the central 50% of the image.
--------
请考虑以下代码:
In [2]: import tensorflow as tf
In [3]: image_raw = tf.placeholder(tf.string)
In [4]: image = tf.image.decode_jpeg(image_raw, channels=3)
In [5]: crop = tf.image.central_crop(image, central_fraction=0.5)
In [6]: init_op = tf.global_variables_initializer()
In [7]: sess = tf.Session()
In [8]: sess.run(init_op)
In [9]: image_np, crop_np = sess.run([image, crop],
...: feed_dict={image_raw: open("/tmp/test.jpg", 'rb').read()})
In [10]: image_np.shape
Out[10]: (456, 450, 3)
原始图片尺寸为456x450
In [11]: crop_np.shape
Out[11]: (228, 226, 3)
裁剪尺寸为228x226
其中面积比为:
In [12]: 228*226 / (456*450.)
Out[12]: 0.2511111111111111
不是我预期的0.5。有人可以帮忙解释一下吗?
答案 0 :(得分:0)
正如@Wes Doyle指出的那样,它返回每个维度的50%,这与评论中的插图一致,原始大小为4x8(4" |"符号和8&#34 ; - "标志),裁剪尺寸为2x4(2" X"垂直,4" X"水平)。