当前位置:网站首页>Use tf.image.resize() and tf.image.resize_with_pad() to resize images
Use tf.image.resize() and tf.image.resize_with_pad() to resize images
2022-08-03 22:54:00 【Erosion_ww】
tf.image.resize和tf.image.resize_with_pad使用方法
tf.image.resize()
作用
~~~~ Resize the image using the specified method.
~~~~ If the original aspect ratio is different from the size,The resized image will be distorted. to avoid distortion,可用tf.image.resize_with_pad()
参数
tf.image.resize(
images, # 形状 [batch, height, width, channels] 的 4-D tensor or shape [height, width, channels] 的 3-D 张量.
size, # 2 个元素的一维 int32 张量:new_height,new_width. 图像的新尺寸.
method=ResizeMethod.BILINEAR, # 一个 image.ResizeMethod,or the equivalent string. The default is bilinear.
preserve_aspect_ratio=False, # Whether to preserve the aspect ratio.
# true,The image will be resized to fit the size,While preserving the aspect ratio of the original image.
# If the size is larger than the current size of the image,则放大图像. 默认为false.
antialias=False, # Whether to use when downsampling the imageanti-aliasing filter.
name=None # 此操作的名称(可选).
)
~~~~ 其中,Image.ResizeMethod()的选项有:
~~~~ • bilinear: 双线性插值.若antialisa为true,Then it becomes the radius when downsampling1的hat/tent filter.
~~~~ • lanczos3: Lanczos kernel with radius 3.High quality practical filter,But there may be someringing,Especially on composite images.
~~~~ • lanzos5:Lanczos kernel with radius 5.Very high quality filter,But there may be stronger onesringing.
~~~~ • bicubic:三次插值.相当于Catmull-Rom kernel,与lanczos3kernel相比较,质量相当好,速度更快,Especially when upsampling.
~~~~ • gaussian:Gaussian kernel with radius 3, sigma = 1.5 / 3.0.
~~~~ • nearest:最近邻插值. When used with nearest neighbor interpolation,antialias无效.
~~~~ • area:Antialiased resampling using region interpolation. When used with area interpolation,antialias没有效果.
~~~~ •mitchellcubic:Mitchell-Netravali Cubic non-interpolating filter. For composite images(Especially those images that lack proper pre-filtering),ringing比Cubic interpolant of Keys少,Not as sharp.
返回值
~~~~ If images was 4-D, a 4-D float Tensor of shape [batch, new_height, new_width, channels].
~~~~ If images was 3-D, a 3-D float Tensor of shape [new_height, new_width, channels].
例子
import tensorflow as tf # 导入tensorflow
img_path ='C:\\Users\\xxx\\.keras\\datasets\\flower_photos\\roses\\6158504080_b844a9ae05.jpg' # 输入图片路径
img_raw = tf.io.read_file(img_path) # 读取图片内容,返回值时string的tensor
img_tensor = tf.image.decode_image(img_raw) # 对输入的string的tensor进行解码
print(img_tensor.shape) # Enter the decoded image shape
print(img_tensor.dtype) # Enter the decoded image representation type
img_final = tf.image.resize(img_tensor, [192, 192]) # 调整图像大小
print(img_final.shape) # Enter the resized image size
(333, 500, 3)
<dtype: 'uint8'>
(192, 192, 3)
tf.image.resize_with_pad()
作用
~~~~ Resize and fill the image to the target width and height.
~~~~ No distortion by keeping the aspect ratio the same,Resize the image to the target width and height. If the target size does not match the image size,will resize the image,It is then padded with zeros to match the requested dimensions.
参数
tf.image.resize_with_pad(
image, # 形状 [batch, height, width, channels] 的 4-D tensor or shape [height, width, channels] 的 3-D 张量.
target_height, # 目标高度
target_width, # 目标宽度
method=ResizeMethod.BILINEAR, # The method used to resize the image. 见 image.resize()
antialias=False # Whether to use antialiasing when resizing. 参见“image.resize()”.
)
返回值
~~~~ Resized and padded image.
~~~~ If images was 4-D, a 4-D float Tensor of shape [batch, new_height, new_width, channels].
~~~~ If images was 3-D, a 3-D float Tensor of shape [new_height, new_width, channels].
主要参考:
tf.image.resize | TensorFlow Core v2.9.1 (google.cn)
tf.image.resize_with_pad | TensorFlow Core v2.9.1 (google.cn)
边栏推荐
- noip preliminary round
- Take an example of a web worker
- [b01lers2020]Life on Mars
- CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应
- start with connect by implements recursive query
- Walk the Maze BFS
- Create function report error, prompting DECLARE definition syntax problem
- With 4 years of work experience, the 5 communication methods between multi-threads can't be said, can you believe it?
- HCIP BGP实验报告
- 关于IDO预售系统开发技术讲解丨浅谈IDO预售合约系统开发原理分析
猜你喜欢

Deep integration of OPC UA and IEC61499 (1)

【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve

软测人每个阶段的薪资待遇,快来康康你能拿多少?

网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)

Zilliz 2023 秋季校园招聘正式启动!

LabVIEW代码生成错误 61056

The principle and use of AOSP CameraLatencyHistogram

2022-08-02 mysql/stonedb slow SQL-Q18 - memory usage surge analysis

Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret

First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
随机推荐
Zilliz 2023 Fall Campus Recruitment Officially Launched!
Cloud platform construction solutions
使用tf.image.resize() 和tf.image.resize_with_pad()调整图像大小
noip初赛
[RYU] rest_router.py source code analysis
什么是memoization,它有什么用?
for loop exercises
Golang Chapter 1: Getting Started
UVa 437 - The Tower of Babylon (White Book)
Nine ways to teach you to read the file path in the resources directory
图的基础概念
Embedded Systems: GPIO
最小化安装debian11
start with connect by implements recursive query
Makefile
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
LabVIEW代码生成错误 61056
IELTS essay writing template
Deep integration of OPC UA and IEC61499 (1)