tf.image.crop_and_resize()使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yql_617540298/article/details/82978496

tf.image.crop_and_resize()

官方链接:https://tensorflow.google.cn/api_docs/python/tf/image/crop_and_resize

用法

tf.image.crop_and_resize(
    image,
    boxes,
    box_ind,
    crop_size,
    method='bilinear',
    extrapolation_value=0,
    name=None
)

参数

  • image:张量。必须是下列类型之一:uint8uint16int8int16int32int64halffloat32float64
  • boxesfloat32类型张量,指需要划分的区域,输入格式为 [[ymin,xmin,ymax,xmax]] ;
  • box_indint32类型张量;
  • crop_size:裁剪尺寸;
  • method:方法,"bilinear", "nearest"。

例子

import tensorflow as tf
import matplotlib.pyplot as plt 
img = plt.imread('F:aa.jpg')
shape = img.shape
img = img.reshape([1,shape[0], shape[1], shape[2]])
a = tf.image.crop_and_resize(img,[[0.5,0.5,0.6,0.2],[0.5,0.5,1.3,0.9]],
                             box_ind=[0,0],crop_size=(100,100))
sess = tf.Session()
b = a.eval(session = sess)
plt.imshow(b[0]/255)
plt.imshow(b[0].astype('uint8'))
img = plt.imread('F:aa.jpg')#代表路径

结果

猜你喜欢

转载自blog.csdn.net/yql_617540298/article/details/82978496