Convert grayscale png to RGB png image

2019-09-21 06:29发布

问题:

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

回答1:

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:

  • Using CNNs and considering the colorization as a regression problem: Let there be Color!
  • Using CNNs and considering the colorization as a classification problem: Colorful Image Colorization
  • Using GANs : cycle-gan


回答2:

GIMP, Menu image -> Mode -> RGB mode