原圖像
圖像加載
原碼:
import matplotlib.pyplot as plt
import tensorflow as tf
image_path = "/xxx/timg.jpeg"
image_data = tf.gfile.FastGFile(image_path,'r').read()
with tf.Session() as sess:
image_data = tf.image.decode_jpeg(image_data)
print(image_data.eval())
列印出的圖像像素點
[[[ ]
[ ]
[ ]
...,
[ ]
[ ]
[ ]]
[[ ]
[ ]
[ ]
...,
[ ]
[ ]
[ ]]
[[ ]
[ ]
[ ]
...,
圖像修剪
resize_image = tf.image.resize_images(image_data,[,],method=1)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.resize_image_with_crop_or_pad(image_data,,)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.resize_image_with_crop_or_pad(image_data,,)
plt.imshow(resize_image.eval())
plt.show()
圖像翻轉
resize_image = tf.image.flip_left_right(image_data)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.flip_up_down(image_data)
plt.imshow(resize_image.eval())
plt.show()
圖像亮度調整
resize_image = tf.image.adjust_brightness(image_data,-)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.adjust_brightness(image_data,+)
plt.imshow(resize_image.eval())
plt.show()
圖像對比度調整
resize_image = tf.image.adjust_contrast(image_data,)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.adjust_contrast(image_data,-)
plt.imshow(resize_image.eval())
plt.show()
圖像飽和度調整
resize_image = tf.image.adjust_saturation(image_data,-)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.adjust_saturation(image_data,)
plt.imshow(resize_image.eval())
plt.show()
圖像存儲
resize_image = tf.image.adjust_saturation(image_data,)
encode_image = tf.image.encode_jpeg(resize_image)
with tf.gfile.GFile("/home/abig/vscode/project1/save.jpeg","wb") as f:
f.write(encode_image.eval())
存儲後的圖檔