def pixel2img(xy, ax=None):
    """
    Plot create by SPM.show can be either in pixels or real unit.
    This function return the input in case the plot is in pixels
    or calculate and return the real unit coordinate of the corresponding pixel.
    """
    import matplotlib.pyplot as plt
    if ax is None:
        ax = plt.gca()
    if hasattr(ax, 'isPixel'):
        if not ax.isPixel:
            pixel_shape = ax.images[0].get_array().shape
            extent = ax.images[0].get_extent()
            eW = extent[1] - extent[0]
            eH = extent[3] - extent[2]
            return xy[0] * eW / pixel_shape[1], xy[1] * eH / pixel_shape[0]
    return xy
