Converting 4channel images to RGB

Hi all,
Is there any simple way to covert 4 channel images into RGB inside transforms? Any help is appreciated.

Thanks

It depends what the 4 channels in the original input represent. E.g. if the 4th channel is the alpha channel and you don’t want to use it, you could transform the image using PIL or just slice the tensor:

transform = transforms.Lambda(lambda x: x[:3])

x = torch.randn(4, 224, 224)
out = transform(x)

assuming the format is RGBA.

1 Like