Discarding alpha channel from images stored as Numpy arrays

耗尽温柔 提交于 2021-02-06 07:15:48

问题


I load images with numpy/scikit. I know that all images are 200x200 pixels.

When the images are loaded, I notice some have an alpha channel, and therefore have shape (200, 200, 4) instead of (200, 200, 3) which I expect.

Is there a way to delete that last value, discarding the alpha channel and get all images to a nice (200, 200, 3) shape?


回答1:


Just slice the array to get the first three entries of the last dimension:

image_without_alpha = image[:,:,:3]


来源:https://stackoverflow.com/questions/35902302/discarding-alpha-channel-from-images-stored-as-numpy-arrays

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!