<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def branchpoints(image, mask=None):
    '''Remove all pixels from an image except for branchpoints
    
    image - a skeletonized image
    mask -  a mask of pixels excluded from consideration
    
    1 0 1    ? 0 ?
    0 1 0 -> 0 1 0
    0 1 0    0 ? 0
    '''
    global branchpoints_table
    if mask is None:
        masked_image = image
    else:
        masked_image = image.astype(bool).copy()
        masked_image[~mask] = False
    result = table_lookup(masked_image, branchpoints_table, False, 1)
    if not mask is None:
        result[~mask] = image[~mask]
    return result