Skip to content

Instantly share code, notes, and snippets.

@ctmakro
Last active April 15, 2024 03:22
Show Gist options
  • Save ctmakro/3ae3cd9538390b706820cd01dac6861f to your computer and use it in GitHub Desktop.
Save ctmakro/3ae3cd9538390b706820cd01dac6861f to your computer and use it in GitHub Desktop.
Display numpy ndarray as Image in Jupyter/IPython notebook
# if input image is in range 0..1, please first multiply img by 255
# assume image is ndarray of shape [height, width, channels] where channels can be 1, 3 or 4
def imshow(img):
import cv2
import IPython
_,ret = cv2.imencode('.jpg', img)
i = IPython.display.Image(data=ret)
IPython.display.display(i)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@whyboris
Copy link

whyboris commented Aug 4, 2018

Thank you! Image shows directly in Jupyter Lab ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment