def METHOD_NAME(image, valP50, valPslope=1, neighP50=.5, neighSlope=1, mask=None, nIters=10, out = None):
    """segment an image based on both intensity and neighbourbood relationships"""
    #if no mask then use default
    if mask is None:
        neighbourMask = genDefaultMask(image.ndim)
    else:
        neighbourMask = mask
    #print neighbourMask.shape
    nNeighbours = neighbourMask.sum()
    neighP50 *= nNeighbours
    neighSlope /= nNeighbours
    #calculate probability that a pixel belongs to object based on it's intensity
    imP = (image/(2*valP50) - 0.5)*valPslope + 0.5
    if out is None:
        out = np.zeros_like(image)
    #create initial object segmentation
    #print out.shape, imP.shape
    out[:] = (imP > 0.5)[:]
    #now do the simulated annealing bit
    for i in range(nIters):
        #calculate probability of pixel given neighbours
        pNeigh = (ndimage.convolve(out.astype('f'), neighbourMask) - neighP50)*neighSlope
        #total probability is sum of neighbour and intensity based probabilities
        pObj = imP + pNeigh
        #create our new estimate of the object
        out[:] =  pObj > .5
    return out