当前位置:网站首页>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()
边栏推荐
- All the ArrayList knowledge you want to know is here
- Migrate data from SQL files to tidb
- 2022.02.13 - NC001. Reverse linked list
- Synchronized solves problems caused by sharing
- 堆排序详解
- Beijing invitation media
- sublime text中conda环境中plt.show无法弹出显示图片的问题
- sublime text的编写程序时的Tab和空格缩进问题
- Research Report on Market Research and investment strategy of microcrystalline graphite materials in China (2022 Edition)
- Use dumping to back up tidb cluster data to S3 compatible storage
猜你喜欢
【MySQL】鎖
Roguelike游戏成破解重灾区,如何破局?
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
MySQL learning record 10getting started with JDBC
win10系统中的截图,win+prtSc保存位置
Let the bullets fly for a while
Cisp-pte practice explanation
ESP series pin description diagram summary
PLT in Matplotlib tight_ layout()
Pointer advanced --- pointer array, array pointer
随机推荐
Function coritization
704 二分查找
MySQL learning record 07 index (simple understanding)
Mobile Test Engineer occupation yyds dry goods inventory
C language custom type: struct
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
2022.02.13 - NC003. Design LRU cache structure
Erc20 token agreement
win10系统中的截图,win+prtSc保存位置
Roguelike游戏成破解重灾区,如何破局?
On the inverse order problem of 01 knapsack problem in one-dimensional state
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
移位运算符
China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
LDAP应用篇(4)Jenkins接入
Golang force buckle leetcode 1020 Number of enclaves
leetcode刷题 (5.31) 字符串
Process of obtaining the electronic version of academic qualifications of xuexin.com
电脑F1-F12用途
Tidb backup and recovery introduction