Display an image with Python

前端 未结 9 1590
后悔当初
后悔当初 2020-12-23 00:21

I tried to use IPython.display with the following code:

from IPython.display import display, Image
display(Image(filename=\'MyImage.png\'))

相关标签:
9条回答
  • 2020-12-23 00:57

    It's simple Use following pseudo code

    from pylab import imread,subplot,imshow,show
    
    import matplotlib.pyplot as plt
    
    image = imread('...')  // choose image location
    
    plt.imshow(image)
    

    plt.show() // this will show you the image on console.

    0 讨论(0)
  • 2020-12-23 01:00

    If you use matplotlib, you need to show the image using plt.show() unless you are not in interactive mode. E.g.:

    plt.figure()
    plt.imshow(sample_image) 
    plt.show()  # display it
    
    0 讨论(0)
  • 2020-12-23 01:08

    Using Jupyter Notebook, the code can be as simple as the following.

    %matplotlib inline
    from IPython.display import Image
    Image('your_image.png')
    

    Sometimes you might would like to display a series of images in a for loop, in which case you might would like to combine display and Image to make it work.

    %matplotlib inline
    from IPython.display import display, Image
    for your_image in your_images:
        display(Image('your_image'))
    
    0 讨论(0)
提交回复
热议问题