How can I get only rgb of plt.imread?

Viewed 1579

Hello I am reading an image with

plt.imread('photo.png') 

and this returns the following shape:

100, 100, 4

What can I do to only get the rgb, that is to say

100, 100, 3

1 Answers

Try getting the first three values i.e. the RGB sequence (100, 100, 3) from the RGBA sequences (100, 100, 4) using the following where you leave out the alpha parameter. As per the docs, imread returns (M, N, 3) for RGB images and (M, N, 4) for RGBA images.

rgb = plt.imread('photo.png')[:,:,:3]
Related