当前位置:网站首页>Image reading: image open(ImgPath)
Image reading: image open(ImgPath)
2022-06-23 16:15:00 【Growth of code Xiaobai】
from PIL import Image
utilize img = Image.open(ImgPath) The open picture is PIL Type of , It comes with resize function . because pytorch The order is (batch,c,h,w), So we need to do PIL Type to numpy Type conversion ,tensorflow,numpy The order is (batch,h,w,c):
# Load Image
img_fn = os.path.join(self.input_path, filenames)
img = Image.open(img_fn) # RGB( Default )
# img.show()
# resize/crop if needed:[128*128*3]
if self.input_size != 0:
height = width = self.input_size
img = img.resize((height, width), Image.BILINEAR)
# take PIL Type conversion to numpy type
img = np.array(img).uint8() # H*W*C
or
# Load Image
img_fn = os.path.join(self.input_path, filenames)
img = Image.open(img_fn) # RGB( Default )
# img.show()
# take PIL Type conversion to numpy type
img = np.array(img).uint8() # H*W*C
# resize/crop if needed:[128*128*3]
if self.input_size != 0:
height = width = self.input_size
img = self.resize(img, height, width)
def resize(self, img, height, width, centerCrop=True, interp='bilinear'):
imgh, imgw = img.shape[0:2]
if centerCrop and imgh != imgw:
# center crop
side = np.minimum(imgh, imgw)
j = (imgh - side) // 2
i = (imgw - side) // 2
img = img[j:j + side, i:i + side, ...]
# Change image size and hide normalized to 0-255 Section operation
img = scipy.misc.imresize(img, [height, width], interp=interp)
return img
from scipy.misc import imread
utilize img = imread(ImgPath) The open picture is numpy Type of , And it's also RGB Format . But because of scipy In version 1.3.0 Then it was canceled imread function , If you download a lower version scipy Will be with tensorflow There are various incompatibilities , It's troublesome
边栏推荐
- Array's own method
- 【OpenHarmony】usb gadget 配置hdc功能cfg文件解读
- npm install 问题解决(nvm安装与使用)
- 苹果 iPhone、三星手机等电子产品开始经平行进口渠道进入俄罗斯
- pytorch:模型的保存与导出
- 【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
- 《ThreadLocal》
- R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的gt_sparkline函数以表格的形式可视化分组数据的线图(line plot)、包含分组类别、分组类别对应的数值
- 批量注册组件
- 腾讯的技术牛人们,是如何完成全面上云这件事儿的?
猜你喜欢

【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)

【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍

2022九峰小学(光谷第二十一小学)生源摸底

【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线

window远程桌面连接互传文件加速小技巧
![[tcapulusdb knowledge base] Introduction to new models of tcapulusdb](/img/2a/1d7f12c99b92d143e142ade8bc90f9.png)
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb

513. Find Bottom Left Tree Value

【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)

Sleuth + Zipkin

万字攻略,详解腾讯面试(T1-T9)核心技术点,面试题整理
随机推荐
SSRS页面配置Postgresql data source的方法
子级文件拖到上一级
Analysis of TCP three-time handshake and four-time handshake
Array's own method
139. word splitting
再突破!阿里云进入Gartner云AI开发者服务挑战者象限
How did Tencent's technology bulls complete the overall cloud launch?
Can the hbuilderx light theme be annotated?
MySQL中json_extract函数说明
Tips for using JS objects
提高效率 Or 增加成本,开发人员应如何理解结对编程?
CA认证和颁发吊销证书
Block, non block, multiplexing, synchronous, asynchronous, bio, NiO, AIO
Apache commons tool class
XML
万字攻略,详解腾讯面试(T1-T9)核心技术点,面试题整理
腾讯的技术牛人们,是如何完成全面上云这件事儿的?
Object
MES在流程和离散制造企业的15个差别(上)
Drag the child file to the upper level