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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With