You can use PIL library for this purpose. It makes the task very easier.
You should use convert() method:
from PIL import Image Â open_image = Image.open("image_name.png") rgb_image = open_image.convert('RGB') rgb_image.save('output_image.jpg')
For more information: http://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.convert
This method is very useful,when you are working on object detection method.Because model can create error if you try to use two different types of images in the training dataset.