当前位置:网站首页>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)
边栏推荐
- 举一个 web worker 的例子
- 2022-08-03 oracle执行慢SQL-Q17对比
- .NET6之MiniAPI(十四):跨域CORS(上)
- IELTS essay writing template
- Storage engine written by golang, based on b+ tree, mmap
- V8中的快慢数组(附源码、图文更易理解)
- Kotlin - extension functions and operator overloading
- Quickly build a website with static files
- 最小化安装debian11
- [2022强网杯] polydiv和gamemaster
猜你喜欢
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
Cloud platform construction solutions
Summary bug 】 【 Elipse garbled solution project code in Chinese!
Click the icon in Canvas App to generate PDF and save it to Dataverse
2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
代码随想录笔记_动态规划_416分割等和子集
Embedded Systems: Clocks
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
encapsulation, package, access modifier, static variable
随机推荐
Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!
MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
Zilliz 2023 Fall Campus Recruitment Officially Launched!
【开源框架】国内首个通用云计算框架,任意程序都可做成云计算。
Basic Concepts of Graphs
.NET6之MiniAPI(十四):跨域CORS(上)
FinClip,助长智能电视更多想象空间
Republish the lab report
Kotlin - 扩展函数和运算符重载
log4j-slf4j-impl cannot be present with log4j-to-slf4j
使用tf.image.resize() 和tf.image.resize_with_pad()调整图像大小
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
Analysys Analysis: The transaction scale of China's online retail B2C market in Q2 2022 will reach 2,344.47 billion yuan
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
Zilliz 2023 秋季校园招聘正式启动!
Pytest学习-setup/teardown
2019年10月SQL注入的两倍
What is the difference between the generator version and the viewer version?