return the index closest to point [pt] in an array [arr]
    within a given kernel size [kSize] that is not zero

def closestNonZeroIndex(pt, arr, kSize=21):
    """
    return the index closest to point [pt] in an array [arr]
    within a given kernel size [kSize] that is not zero
    """
    assert kSize % 2 == 1, 'need odd kernel size'

    hk = int(kSize / 2)
    ipt = np.asarray(pt, dtype=int)
    # array slice of shape kSize around ipt:
    r = [slice(max(0, p - hk),
               min(s, p + hk + 1)) for p, s in zip(ipt, arr.shape)]

    # sliced array:
    arrr = arr[tuple(r)]
    # all indices that are non zero:
    ind = np.transpose(np.nonzero(arrr))
    if not len(ind):
        # nothing found
        return None
    # pos of ipt within array slice:
    center = [p - s.start for p, s in zip(ipt, r)]
    ind -= center
    # index of minimum distance:
    m = np.argmin(norm(ind, axis=-1))
    return ipt + ind[m]