Would it be possible to have to_pil_image work for 2D arrays and convert them to an L PIL Images?
Currently, it converts 3 dimensional arrays to RGB if they have 3 channels and to L if they have one channel.
However, like in the code below, to_pil_image complains if it is called on a 2D array.
Would it be simpler if 2D arrays are assumed to be single channel images so that to_pil_image converts them to L PIL images ? Thanks.
ipdb> import torchvision.transforms.functional as FT
ipdb> FT.to_pil_image(_points[:,:,0])
*** IndexError: tuple index out of range
ipdb> FT.to_pil_image(_points[:,:,:1])
<PIL.Image.Image image mode=L size=640x480 at 0x7FD4947341D0>
@IssamLaradji I guess this could be made possible, but when you convert back to a tensor you will get a [1xHxW] tensor as the generic fromat in torch is batch x channels x height x width for images.
I see! I guess it's better to keep it consistent this way. Thanks ! :)
@alykhantejani may be torchvision should report something else than IndexError: tuple index out of range ?
--> 108 if npimg.shape[2] == 1:
109 expected_mode = None
110 npimg = npimg[:, :, 0]
for example, check npimg.ndim == 3 here and raise about what kind of input we need.
Most helpful comment
@alykhantejani may be torchvision should report something else than
IndexError: tuple index out of range?for example, check
npimg.ndim == 3here and raise about what kind of input we need.