在Tensorflow中通过函数来支持图像的翻转问题;
tf.image.flip_up_down(img_data) #为图像上下翻转
tf.image.flip_left_right(img_data) #为图像左右翻转
tf.image.transpose_image(img_data) #为图像沿对角线翻转
tf.image.random_flip_up_down(img_data) #以一定概率上下翻转图像
tf.image.random_flip_left_right(img_data) #以一定概率左右翻转图像
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
image_raw_data = tf.gfile.GFile('D:/path/to/picture/8.jpg','rb').read() #加载原始图像
with tf.Session() as sess:
img_data = tf.image.decode_jpeg(image_raw_data)
plt.imshow(img_data.eval())
plt.show()
flipped = tf.image.flip_up_down(img_data) #上下翻转图像
plt.imshow(flipped.eval())
plt.show()后面几个函数的实现只需要调换后三行代码;
结果:

本文介绍了在Tensorflow中实现图像翻转的各种方法,包括上下翻转、左右翻转、对角线翻转以及随机翻转,这些函数能够帮助开发者在图像处理任务中灵活变换图像方向。
最低0.47元/天 解锁文章
271

被折叠的 条评论
为什么被折叠?



