sneka
sneka

Reputation: 21

Convert grayscale png to RGB png image

I have a dataset of medical images in grayscale Png format which must be converted to RGB format. Tried many solutions but in vain.

Upvotes: 0

Views: 1478

Answers (2)

schlodinger
schlodinger

Reputation: 559

If you want to just convert the format, the following method will help you:

In python3, using PILLOW and Numpy:

From PIL import Image
import numpy as np

im = Image.open(path/to/image, 'r').convert('L')
im = np.stack((im,)*3, axis=-1)
im = Image.fromarray(im)
im.save(path/to/save)

But if you want to colorize the image, know that colorization is an well-known image translation problem. Even if multiple approachs exist depending on the domain, I don't know any method that colorize any kind of images.

Some ways of doing so is to train a neural network, but for that, you need to have a dataset of B/W and colored images. Here are some approaches:

Upvotes: 1

Jingshao Chen
Jingshao Chen

Reputation: 3485

GIMP, Menu image -> Mode -> RGB mode

Upvotes: 1

Related Questions