def extent(xll, yll, cellsize, nrows, ncols, scale=1.0, registration=
    'gridlines'):
    """
    Return the extent (xmin,xmax,ymin,ymax) of an image given the coordinates of
    the lower-left corner, the cellsize and the numbers of rows and columns. 
    Registration option controls whether the coordinates indicate the position
    of the centre of the pixels ('pixels') or the corner ('gridlines').
    
    Returns
    -------
    (xmin,xmax,ymin,ymax) 
    """
    if registration == 'gridlines':
        xmin = xll * scale
        xmax = (xll + (ncols - 1) * cellsize) * scale
        ymin = yll * scale
        ymax = (yll + (nrows - 1) * cellsize) * scale
    else:
        xmin = (xll - cellsize / 2.0) * scale
        xmax = (xmin + ncols * cellsize) * scale
        ymin = (yll - cellsize / 2.0) * scale
        ymax = (ymin + nrows * cellsize) * scale
    return xmin, xmax, ymin, ymax
