tensorflow實(shí)現(xiàn)圖像的裁剪和填充方法
tensorflow里面提供了實(shí)現(xiàn)圖像進(jìn)行裁剪和填充的函數(shù),就是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()
結(jié)果:

以上這篇tensorflow實(shí)現(xiàn)圖像的裁剪和填充方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python自動(dòng)化辦公Excel模塊openpyxl原理及用法解析
這篇文章主要介紹了Python自動(dòng)化辦公Excel模塊openpyxl原理及用法解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
Python定時(shí)任務(wù)APScheduler安裝及使用解析
這篇文章主要介紹了Python定時(shí)任務(wù)APScheduler安裝及使用解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
關(guān)于Pycharm無(wú)法debug問(wèn)題的總結(jié)
今天小編就為大家分享一篇關(guān)于Pycharm無(wú)法debug問(wèn)題的總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-01-01

