简体   繁体   中英

Conversion of Image using MatplotLib or Pillow

I have an image of dimension (1000,1000,4) which I want to convert in (1000,1000,3). How to do this using either matplotlib or pillow module in python?

Normally, you would save your array as a numpy array, flatten it, and then reshape it. However you cannot convert a (1000,1000,4) into (1000,1000,3). A (1000,1000,4) has 1000 x 1000 x 4 elements which can not be converted into an array which stores 1000 x 1000 x 3 elements. You will have to get rid of some elements.

import numpy as np
arr = np.array(your_array) 
arr.flatten().reshape((x dim,y dim ,z dim))

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