Reputation: 12333
I am using an Anaconda distribution of Python with stuff like numpy
, scipy
, and scikit-image
.
When I call:
from skimage import io
img = io.imread('myimage.png')
It ignores my alpha channel and returns the image as an array with shape (W, H, 3)
instead of (W, H, 4)
. How can I get the alpha channel of the image?
Upvotes: 5
Views: 3820
Reputation: 2047
Some PNG images include alpha channel from the go. So just simple
from skimage import io
img = io.imread('myimage.png')
returns (W, H, 4)
.
Some times, with PNG or JPG images you don't get aRGB, you can try
import cv2
img = cv2.imread('myimage.png')
img_a = cv2.cvtColor(img, cv2.COLOR_RGB2RGBA)
print(img_a.shape) #(W, H, 4)
As in both skimage.io
and cv2.imread
return a <class 'numpy.ndarray'>
you can use both interchangeably for any operation.
Upvotes: 2