Concatenate two images [Android]

The input to the network is 4 channel tensor. For that, I am using bitmap to read two images (one is gray scale and the other is rgb). Any idea on how to concatenate in a tensor form?

Once you’ve loaded each image and transformed it to a tensor in the shape [channels, height, width], you could concatenate it with torch.cat as seen here:

gray = torch.randn(1, 24, 24)
rgb = torch.randn(3, 24, 24)
x = torch.cat((gray, rgb), dim=0)
print(x.shape)
> torch.Size([4, 24, 24])
1 Like