python - How to use imageio imread to get a multi channel array (RGB) from a single channel image (grayscale)?

python – How to use imageio imread to get a multi channel array (RGB) from a single channel image (grayscale)?

python – How to use imageio imread to get a multi channel array (RGB) from a single channel image (grayscale)?

Following the documentation link you provided, you can see a navigation item Docs for the formats quite prominent on the left side. For example, lets check the PNG format entry, since PNG supports single channel images. Theres a section Parameters for reading: You need to provide a proper Pillow format string, for RGB images, its RGB. The parameter to be used is called pilmode. Lets check that:

import imageio

im = imageio.imread(path/to/some/singlechannelimage.png)
print(im.shape)

im3d = imageio.imread(path/to/some/singlechannelimage.png, pilmode=RGB)
print(im3d.shape)

If I run that for some single channel PNG, I get:

(639, 379)
(639, 379, 3)

Thats what you want, I suppose.

----------------------------------------
System information
----------------------------------------
Platform:      Windows-10-10.0.16299-SP0
Python:        3.8.5
imageio:       2.9.0
----------------------------------------

python – How to use imageio imread to get a multi channel array (RGB) from a single channel image (grayscale)?

Related posts on python  :

Leave a Reply

Your email address will not be published.