tensorflow实现图像的裁剪和填充方法
tensorflow里面提供了实现图像进行裁剪和填充的函数,就是tf.image.resize_image_with_crop_or_pad(img,height,width )。img表示需要改变的图像,height是改变后图像的高度,width是宽度。
例如:
import matplotlib.pyplot as plt; import tensorflow as tf; image_raw_data_jpg = tf.gfile.FastGFile('11.jpg', 'r').read() with tf.Session() as sess: img_data_jpg = tf.image.decode_jpeg(image_raw_data_jpg) img_data_jpg = tf.image.convert_image_dtype(img_data_jpg, dtype=tf.float32) crop = tf.image.resize_image_with_crop_or_pad(img_data_jpg, 500, 500) pad = tf.image.resize_image_with_crop_or_pad(img_data_jpg, 2000, 2000) plt.figure(1) plt.imshow(crop.eval()) plt.figure(2) plt.imshow(pad.eval()) plt.show()
结果:
相关推荐
Micusd 2020-11-19
xjtukuixing 2020-10-27
lybbb 2020-10-15
lybbb 2020-09-29
ghjk0 2020-09-24
yamaxifeng 2020-09-09
GDGYZL 2020-08-28
lybbb 2020-08-28
Icevivian 2020-08-25
comwayLi 2020-08-16
carbon0 2020-08-16
源式羽语 2020-08-09
sherry颖 2020-08-01
songbinxu 2020-07-19
sherry颖 2020-07-18
Niteowl 2020-07-15
Kindle君 2020-07-15
源式羽语 2020-07-04
源式羽语 2020-06-28