Why must 'fillcolor' be an int? (torchvision.transforms.RandomAffine)


I am using torchvision.transforms.RandomAffine to do some data augmentation. My inputs are RGB images. However, I don’t really understand one argument, fillcolor, the color for the area outside the transform in the output image. It seems fillcolor must be an integer, but what if I want to fill the area with some RGB value? Is there any way to convert an RGB (a tuple of length 3) to an int?

Thank you in advance!

You can pass a RGB color code as a tuple to this function:

trans = transforms.RandomAffine(45, fillcolor=(0, 0, 255))
img = TF.to_pil_image(torch.randn(3, 100, 100))

This will use blue to fill the pixels.
Could you create an issue so that the docs might be updated, as this seems indeed to be confusing.

Hi ptrblck, thank you for your reply.
I updated my pillow version and it works!