on the other hand it should reduce the code to this:

    conv = np.empty_like(image, dtype=np.intp)
    ndimage.convolve(image > 0, selem, mode='constant', cval=1, output=conv)
    return np.equal(conv, np.sum(selem), ...)