当前位置:网站首页>Get the size of the picture

Get the size of the picture

2022-06-12 06:09:00 Just change your name

img.shape It can be up to size
because cv2 After reading img yes numpy array,
img.size It refers to the number after multiplying the width and height channels of the picture ,
You need to specify the dimension to get the width and height channel ,
such as ,np.size(img, 0) refer to h Size ,
np.size(img, 1) w
np.size(img, 2) c This dimension applies to color channel read in , Single channel read in will report an error

Return type ,img.shape return tuple, np.size(img, 0) return int Type digital .


If it is torch Type data
img.shape and img.size() The returned content has the same meaning , All are h, w, c.

Return type , All are torch.size, In square brackets index You can take the size of a dimension .
Specially , If img.size(0) This specifies the dimension , return int Number of types , Follow numpy The same as .

import cv2
raw_img_pth = r"F:\vscode_files\project\segment_side\data\raw_img\segment_side\6236a959d839b.jpg"
img = cv2.imread(raw_img_pth, 0) #  Single channel read in 
print(img.shape) # h, w

import cv2
raw_img_pth = r"F:\vscode_files\project\segment_side\data\raw_img\segment_side\6236a959d839b.jpg"
img = cv2.imread(raw_img_pth, 1) #  Color channel read in  
print(img.shape) # h, w c

import numpy as np

print(type(img))
print(img.size)
print(np.size(img, 0))

import torch

img = torch.from_numpy(img)
print(img.shape)
print(img.size())

output:

(288, 384)
(288, 384, 3)
<class 'numpy.ndarray'>
331776
288
torch.Size([288, 384, 3])
torch.Size([288, 384, 3])

Read and write the dimensions together :

import cv2
import numpy as np

raw_img_pth = r"F:\vscode_files\project\segment_side\data\raw_img\segment_side\6236a959d839b.jpg"
print(cv2.imread(raw_img_pth, 0).shape) #  Single channel read in 

output:

(288, 384)
原网站

版权声明
本文为[Just change your name]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120602569699.html