A Python package that I'm trying to use only works with 3-channel images. If I have a grayscale PNG image, Pillow's Image.open()
naturally reads it as a single-layer image. How can I use Pillow to transform the 1-channel image into a 3-channel RGB image?
Asked
Active
Viewed 2,737 times
3
-
1It's all covered here... https://stackoverflow.com/a/52307690/2836621 – Mark Setchell Oct 22 '20 at 20:34
-
@MarkSetchell thank you – I wouldn't have guessed it from the title of the question, but your answer to _that_ question worked in my case too. Using `im = Image.open("image.jpg").convert('RGB')` is all I needed to do. I don't know whether I should delete the present question, or whether to leave it so that you can post this comment as answer. Does this question seem like it's enough of a duplicate of the other one that it should be deleted? – mhucka Oct 23 '20 at 01:00
-
I'm not sure what to do either! I nearly marked it as a duplicate question but it it isn't really, it's more of an *"equally applicable answer"*! I don't want to repeat the answer and be accused of grabbing points for no effort, but I don't like leaving the question appearing unanswered. Maybe you could edit your question title and add **SOLVED**? I don't know or mind - just glad to have helped. Good luck with your project! – Mark Setchell Oct 23 '20 at 06:38
-
1@MarkSetchell I tried to do that (mark it solved and include an explanation), and someone reverted the question back with the note "Please post answers as an actual answer below" :-(. So, more points for you! Would you be able to write a brief answer, to explain that `img = Image.open("image.png").convert('RGB')` will do what is asked? – mhucka Oct 23 '20 at 22:14
1 Answers
5
The simplest method to convert a single-channel greyscale image into a 3-channel RGB image with PIL is probably like this:
RGB = Image.open('image.png').convert('RGB')
Further discussion and explanation is available here.

Mark Setchell
- 191,897
- 31
- 273
- 432