Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i read an image with Pyplot from memory instead of a file?

This piece of code is working, but I want to avoid the use of the temporal file, i have tried differents ways but not working. Does anyone knows how to do it? or the temp file is mandatory?

from PIL import Image
import matplotlib.pyplot as plt
import numpy as np

...
data = Image.fromarray(np.array(image))
data.save('output/temp.png')
img = plt.imread('output/temp.png')
...

the complete function:

            data = pickle.load(datafile)
            # IMAGES
            image = data['img']
            # LABELS
            label = data['label']
            # SHOW
            data = Image.fromarray(np.array(image))
            data.save('output/temp.png')
            img = plt.imread('output/temp.png')

            # Create a figure. Equal aspect so circles look circular
            fig, ax = plt.subplots(1)
            ax.set_aspect('equal')

            # Show the image
            ax.imshow(img)

            # Now, loop through coord arrays, and create a circle at each x,y pair
            for xx, yy in label:
                circle = plt.Circle((xx, yy), 10)
                ax.add_patch(circle)

            # Show the image
            plt.show()

Because I want to draw circles in an image loaded with numpy:
Drawing circles on image with Matplotlib and NumPy

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But I just want to know how to avoid the use of the temporal file. Is it possible?

>Solution :

you asked the wrong question
I think what you mean is how to show it. because you read it to import it from file to memory. so you can’t read it from memory because it’s already there.
and for that, you just need to use plt.imshow(data, *args)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading