I read the rgb image in tensor lets say “rgb_image” with dimension [1,3,256,256]. How can i convert it into the grey scale image?
Hi cbd!
The most standard way:
grayscale_image = rgb_image.mean (dim = 1)
grayscale_image
will now be of shape torch.Size([1, 256, 256])
.
The idea is that “3” dimension of rgb_image
consists of the three
color channels, r, g, and b. You take their mean (or sum them, if
you prefer) to get the “brightness” of the pixel in question, that is,
its grayscale level.
Best.
K. Frank