简体   繁体   中英

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) ?

I have tried:

labels = labels.transpose(2,0,1).reshape(3,-1)

That didnt give me the desired output.

Thanks

The third element in labels.shape is the number of channels. If you want to change the shape to (1528, 1518) , you could use cv.cvtColor and you will get a gray image.

Here is opencv documentation on cvtColor: https://docs.opencv.org/3.4/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM