Access a plotted output image from a function directly in the "Image.open" command

Hi all, this may not be related to pytorch but any ideas are welcomed. I have a function that plots two images (ground truth and predicted image). I want to access these 2 images directly in the “Image.open()” command in another file when I run the function without having to save the 2 images and passing their paths.

So far, I tried to save the images first and pass their paths to the “Image.open()” which works, but that’s not the functionality I want. I want to access the output images from the function directly in the Image.open() command without having to save the images.