GrayScale to RGB

Can I know how to convert Grayscale images to RGB so I can use a pretrained model on them.

would the answer here be helpful to you?

They just make RGB channel all equal to the grayscale value. I suspect it should be good enough from deep learning perspective, though the actual image can be visually distorted a bit. BTW, if you use a pretrained model, I high recommend you fine tune it a bit. Cause I think it is likely the pretrained model is trained on real RGB image.

torchvisions transforms has a function called torchvision.transforms.Grayscale(num_output_channels=1). See here.

Using num_output_channels=1 this can be used to convert an 3 channel RGB image into a 1 channel grayscale image.

But if used with num_output_channels=3 this creates a 3 channel image with R=G=B.

You can use this function on your 1 channel image to make a 3 channel image where R=G=B, if this is what you want.

1 Like