Search code examples
pythonscikit-imagealpha-transparency

Read transparent images as white background scikit-image python


I've a transparent image (4 channels) where the 4th channel is alpha channel. I want to read the image using skimage.io.imread() method. But if I set pilmode=rgb, then the transparent part becomes black, but I want it to be white. How can I achieve this?


Solution

  • You can do the following:

    import skimage.color
    import skimage.io
    
    image = skimage.io.imread('res/images/image.png')
    image = skimage.color.rgba2rgb(image)