def ensure3d(arr):
    """Turns 2 arrays into 3d arrays with a len(1) 3rd dimension. Allows functions to be
    written for both grayscale and color images."""
    if len(arr.shape) == 3:
        return arr
    elif len(arr.shape) == 2:
        return arr.reshape((arr.shape[0], arr.shape[1], 1))