当前位置:网站首页>Image, CV2 read the conversion and size resize change of numpy array of pictures
Image, CV2 read the conversion and size resize change of numpy array of pictures
2022-07-06 08:32:00 【MAR-Sky】
Several image size modifications and parameter summaries
(from torchvision import transforms as T)
Display different size formats
- Image The type and T Conduct resize The picture of size attribute The order of display parameters is W、H
- cv2 Display of Of shape The order of display parameters is H、W、C
- T.ToTensor()(img), Convert the picture to tensor type , Display is size() Method , for example ,
import numpy as np
from PIL import Image
from torchvision import transforms as T
# import matplotlib.image as Img
img = Image.open('4.jpg')
img_tran = T.Resize((512,256))(img)
print(img_tran.size) #(256, 512)
print(np.array(img_tran).shape) # (512, 256, 3)
img_to = T.ToTensor()(img_tran)
img_to_array = np.array(img_to)
print(img_to.size()) #torch.Size([3, 512, 256])
print(img_to_array.shape) # (3, 512, 256)
- It can be seen that size() Method shows that Channel comes first 了 .
Modify the function parameter order of image size
-T.Resize((H,W))(img)
- img.resize((W,H))、cv2.resize(img_read,(W,H))
Image Picture data and numpy Data conversion
Image Convert the picture to numpy data
np.array(img)
from PIL import Image
import numpy as np
img = Image.open('4.jpg')
img_array = np.array(img)
numpy Data to Image picture
Image.fromarray(img_arr.astype(‘uint8’))
Image.fromarray(np.uint8(img))
from PIL import Image
import numpy as np
img = Image.open('4.jpg')
img_array = np.array(img)
img_image = Image.fromarray(img_arr.astype('uint8'))
Image Dimension display and numpy Of shape Show problems
Image.size attribute It is shown that ** wide 、 high **
img_array.shape attribute , It is shown that ** high 、 wide 、 passageway **
from PIL import Image
from torchvision import transforms as T
import numpy as np
img = Image.open('4.jpg')
img_array = np.array(img)
print(img.size) # (720, 1160)
print(img_arr.shape) # (1160, 720, 3)
plt.figure()
plt.subplot(1,3,1)
plt.imshow(img)
plt.subplot(1,3,2)
plt.imshow(img_array)
plt.show()
img.resize(w, h),T.Resize((h,w))(img),cv2.resize(img,(w,h))
function : Modify the width and height of the read image size
import cv2
import matplotlib.image as Img
from torchvision import transforms as T
img = Image.open('4.jpg')
img_resize = img.resize((512,256))
img_tran = T.Resize((512,256))(img)
img_array = np.array(img)
img_read = cv2.imread('4.jpg')
img_cv2 = cv2.resize(img_read,(512,256))
print(img_resize.size) #(512, 256)
print(img_array.shape) #(1160, 720, 3)
print(img_tran.size) # (256, 512)
print(img_cv2.shape) # (256, 512, 3)
plt.figure()
plt.subplot(1,3,1)
plt.title('img_resize')
plt.imshow(img_resize)
plt.subplot(1,3,2)
plt.title('img_tran')
plt.imshow(img_tran)
plt.subplot(1,3,3)
plt.title('img_cv2')
plt.imshow(img_cv2)
plt.show()
边栏推荐
- tree树的精准查询
- marathon-envs项目环境配置(强化学习模仿参考动作)
- sys.argv
- 【刷题】牛客网面试必刷TOP101
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Golang force buckle leetcode 1020 Number of enclaves
- 2022.02.13 - NC001. Reverse linked list
- logback1.3. X configuration details and Practice
- gcc动态库fPIC和fpic编译选项差异介绍
- Ruffian Heng embedded bimonthly, issue 49
猜你喜欢
Verrouillage [MySQL]
[MySQL] database stored procedure and storage function clearance tutorial (full version)
Use Alibaba icon in uniapp
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached
Cisp-pte practice explanation
Bottom up - physical layer
Ruffian Heng embedded bimonthly, issue 49
堆排序详解
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
Analysis of pointer and array written test questions
随机推荐
Day29-t77 & t1726-2022-02-13-don't answer by yourself
C语言深度解剖——C语言关键字
Wincc7.5 download and installation tutorial (win10 system)
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
生成器参数传入参数
China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
Let the bullets fly for a while
[2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
JS native implementation shuttle box
同一局域网的手机和电脑相互访问,IIS设置
移位运算符
Configuring OSPF load sharing for Huawei devices
2022.02.13 - 238. Maximum number of "balloons"
On the day of resignation, jd.com deleted the database and ran away, and the programmer was sentenced
Tidb backup and recovery introduction
软件卸载时遇到trying to use is on a network resource that is unavailable
深度剖析C语言数据在内存中的存储
The mysqlbinlog command uses
Migrate data from SQL files to tidb