[英]How do I change the dimension of an image from 3D matrix to 2D matrix in python?
I have an image:我有一张图片:
labels = cv2.imread("/Users/vaibhavsaxena/Desktop/corn1 copy.png")
labels.shape
(1528, 1518, 3)
How do I change the shape to (1528, 1518)
?如何将形状更改为
(1528, 1518)
?
I have tried:我努力了:
labels = labels.transpose(2,0,1).reshape(3,-1)
That didnt give me the desired output.那并没有给我想要的 output。
Thanks谢谢
The third element in labels.shape
is the number of channels. labels.shape
中的第三个元素是通道数。 If you want to change the shape to (1528, 1518)
, you could use cv.cvtColor
and you will get a gray image.如果要将形状更改为
(1528, 1518)
,可以使用cv.cvtColor
,您将获得灰色图像。
Here is opencv documentation on cvtColor: https://docs.opencv.org/3.4/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab Here is opencv documentation on cvtColor: https://docs.opencv.org/3.4/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.