def annotate_ellipse(params, ax=None, crop_radius=1.2, **kwargs):
"""Annotates an ellipse on an image
Parameters
----------
params : tuple or dict
either (yr, xr, yc, xc) tuple
or dict with names ['yr', 'xr', 'yc', 'xc']
"""
from matplotlib.patches import Ellipse
ellipse_style = dict(ec='yellow', fill=False)
ellipse_style.update(kwargs)
if isinstance(params, tuple):
yr, xr, yc, xc = params
else:
yr = params['yr']
xr = params['xr']
yc = params['yc']
xc = params['xc']
ax.add_artist(Ellipse(xy=(xc, yc), width=xr*2, height=yr*2,
**ellipse_style))
# crop image around ellipse
ax.set_xlim(xc - crop_radius * xr, xc + crop_radius * xr)
ax.set_ylim(yc + crop_radius * yr, yc - crop_radius * yr)
return ax
评论列表
文章目录