def binary_image_to_lut_indices(x):
    '\n    Convert a binary image to an index image that can be used with a lookup table\n    to perform morphological operations. Non-zero elements in the image are interpreted\n    as 1, zero elements as 0\n\n    :param x: a 2D NumPy array.\n    :return: a 2D NumPy array, same shape as x\n    '
    if (x.ndim != 2):
        raise ValueError('x should have 2 dimensions, not {}'.format(x.ndim))
    if (x.dtype != np.bool):
        x = (x != 0)
    x = np.pad(x, [(1, 1), (1, 1)], mode='constant')
    lut_indices = (((((((((x[:(- 2), :(- 2)] * NEIGH_MASK_NORTH_WEST) + (x[:(- 2), 1:(- 1)] * NEIGH_MASK_NORTH)) + (x[:(- 2), 2:] * NEIGH_MASK_NORTH_EAST)) + (x[1:(- 1), :(- 2)] * NEIGH_MASK_WEST)) + (x[1:(- 1), 1:(- 1)] * NEIGH_MASK_CENTRE)) + (x[1:(- 1), 2:] * NEIGH_MASK_EAST)) + (x[2:, :(- 2)] * NEIGH_MASK_SOUTH_WEST)) + (x[2:, 1:(- 1)] * NEIGH_MASK_SOUTH)) + (x[2:, 2:] * NEIGH_MASK_SOUTH_EAST))
    return lut_indices.astype(np.int32)
Convert a binary image to an index image that can be used with a lookup table
to perform morphological operations. Non-zero elements in the image are interpreted
as 1, zero elements as 0

:param x: a 2D NumPy array.
:return: a 2D NumPy array, same shape as x
def binary_image_to_lut_indices(x):
    '\n    Convert a binary image to an index image that can be used with a lookup table\n    to perform morphological operations. Non-zero elements in the image are interpreted\n    as 1, zero elements as 0\n\n    :param x: a 2D NumPy array.\n    :return: a 2D NumPy array, same shape as x\n    '
    if (x.ndim != 2):
        raise ValueError('x should have 2 dimensions, not {}'.format(x.ndim))
    if (x.dtype != np.bool):
        x = (x != 0)
    x = np.pad(x, [(1, 1), (1, 1)], mode='constant')
    lut_indices = (((((((((x[:(- 2), :(- 2)] * NEIGH_MASK_NORTH_WEST) + (x[:(- 2), 1:(- 1)] * NEIGH_MASK_NORTH)) + (x[:(- 2), 2:] * NEIGH_MASK_NORTH_EAST)) + (x[1:(- 1), :(- 2)] * NEIGH_MASK_WEST)) + (x[1:(- 1), 1:(- 1)] * NEIGH_MASK_CENTRE)) + (x[1:(- 1), 2:] * NEIGH_MASK_EAST)) + (x[2:, :(- 2)] * NEIGH_MASK_SOUTH_WEST)) + (x[2:, 1:(- 1)] * NEIGH_MASK_SOUTH)) + (x[2:, 2:] * NEIGH_MASK_SOUTH_EAST))
    return lut_indices.astype(np.int32)