def _ipython_displayhook(cls, func, fmt='image/png'):
    """ 
    Register func as a displayhook for class `cls`
    """
    import IPython
    formatter = IPython.get_ipython().display_formatter.formatters[fmt]
    return formatter.for_type(cls, func)
