matplotlib - How to add visual annotations to an image using python in a jupyter notebook? -


the overall objective view medical images server, add visual annotations image (i.e., highlighting/circling tumor in red), upload images server annotation sort of metadata.

the viewing/uploading/storing metadata complete, have yet find packages allow me draw on images within jupyter notebooks. either manipulate pixels or create new image on top of displayed image.

i'm displaying image data using matplotlib.

i've seen use of javascript track mouse movement , keystrokes, can't figure out how use advantage. can use package, long works within jupyter.

thanks suggestions @michael_j_ward, found solution. looked through discussions , tutorials read documentation matplotlib axes. came with/altered

import matplotlib.pyplot plt matplotlib.lines import line2d import numpy np import dicom   class annotator(object):     def __init__(self, axes):         self.axes = axes          self.xdata = []         self.ydata = []      def mouse_move(self, event):         if not event.inaxes:             return          x, y = event.xdata, event.ydata          self.xdata.append(x)         self.ydata.append(y)         line = line2d(self.xdata,self.ydata)         line.set_color('r')         self.axes.add_line(line)          plt.draw()      def mouse_release(self, event):         # erase x , y data new line         self.xdata = []         self.ydata = []  path = '../sample.dcm'  data = dicom.read_file(path)  img = data.pixel_array  fig, axes = plt.subplots() axes.imshow(img[0]) plt.axis("off") plt.gray() annotator = annotator(axes) plt.connect('motion_notify_event', cursor.mouse_move) plt.connect('button_release_event', cursor.mouse_release)  axes.plot()  plt.show() 

screenshot

it allows me open images , draw on them highlight or annotate significant portions of image.