Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get only rgb of plt.imread?

Tags:

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

like image 948
Tlaloc-ES Avatar asked May 21 '20 00:05

Tlaloc-ES


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]
like image 106
Sheldore Avatar answered Sep 30 '22 19:09

Sheldore