Skip to content

Instantly share code, notes, and snippets.

@ptweir
Created June 28, 2012 00:04
Show Gist options
  • Save ptweir/3007735 to your computer and use it in GitHub Desktop.
Save ptweir/3007735 to your computer and use it in GitHub Desktop.
function to select a rectangular region of interest of a pylab figure
def selectRectangle(fig):
pts = fig.ginput(2)
pts = np.array(pts)
pts.sort(axis=0)
pts = np.round(pts).astype(int)
return pts
"""
#example usage:
axROI.imshow(frames.mean(2),cmap='gray',origin='lower')
pylab.draw()
ROI = selectRectangle(figROI)
axROI.fill_between(ROI[:,0],ROI[0,1],ROI[1,1],alpha=.1,facecolor='b')
framesROISum = np.sum(np.sum(frames[ROI[0,1]:ROI[1,1],ROI[0,0]:ROI[1,0],:],axis=0),axis=0)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment