tf.image.sample_distorted_bounding_box()函数输出的三个值:begin,size,bbox_for_draw。
其中bbox_for_draw是一个框用来可视化截取的部分的,通过tf.image.draw_bounding_boxes()函数实现。
而前面两个参数用于tf.slice()函数中来直接截取图像。
问题来了
为什么由bbox_for_draw得到的框中的区域,却不是tf.slice()裁剪后的区域的?
这是我的代码:
import tensorflow as tf
import matplotlib.pyplot as plt
image_raw_data=tf.gfile.FastGFile("/path/to/picture.jpg",'rb').read()
with tf.Session() as sess:
boxes = tf.constant([[[0.05,0.05,0.9,0.7],
[0.35,0.47,0.5,0.56]]])
begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
tf.shape(img_data), bounding_boxes=boxes, min_object_covered = 0.4)
batched = tf.expand_dims(tf.image.convert_image_dtype(img_data,tf.float32),0)
image_with_box = tf.image.draw_bounding_boxes(batched,bbox_for_draw)
plt.imshow(image_with_box[0].eval())
plt.show()
distorted_image = tf.slice(img_data,begin,size)
plt.imshow(distorted_image.eval())
plt.show()