tensorflow实现图像的裁剪和填充方法

yipeiwu_com6年前Python基础

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()

结果:

以上这篇tensorflow实现图像的裁剪和填充方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python list多级排序知识点总结

在python3的sorted中去掉了cmp参数,转而推荐“key+lambda”的方式来排序。 如果需要对python的list进行多级排序。有如下的数据: list_num =...

Python学习笔记之lambda表达式用法详解

本文实例讲述了Python学习笔记之lambda表达式用法。分享给大家供大家参考,具体如下: Lambda 表达式 使用 Lambda 表达式创建匿名函数,即没有名称的函数。lambda...

详解Python的Lambda函数与排序

lambda函数是一种快速定义单行的最小函数,是从 Lisp 借用来的,可以用在任何需要函数的地方。下面的例子比较了传统的函数与lambda函数的定义方式。 前几天看到了一行求1000...

pytorch cnn 识别手写的字实现自建图片数据

pytorch cnn 识别手写的字实现自建图片数据

本文主要介绍了pytorch cnn 识别手写的字实现自建图片数据,分享给大家,具体如下: # library # standard library import os # th...

python使用itchat实现手机控制电脑

python使用itchat实现手机控制电脑

本文实例为大家分享了python使用itchat实现手机控制电脑的具体代码,供大家参考,具体内容如下 1.准备材料 首先电脑上需要安装了python,安装了opencv更好(非必需) 如...