def test_multiotsu_more_classes_then_values(): img = cp.ones((10, 10), dtype=cp.uint8) with testing.raises(ValueError): threshold_multiotsu(img, classes=2) img[:, 3:] = 2 with testing.raises(ValueError): threshold_multiotsu(img, classes=3) img[:, 6:] = 3 with testing.raises(ValueError): threshold_multiotsu(img, classes=4)
def test_correlate_sparse_invalid_kernel(mode): image = cp.array([[0, 0, 1, 3, 5], [0, 1, 4, 3, 4], [1, 2, 5, 4, 1], [2, 4, 5, 2, 1], [4, 5, 1, 0, 0]], dtype=float) # invalid kernel size invalid_kernel = cp.array([0, 1, 2, 4]).reshape((2, 2)) with testing.raises(ValueError): correlate_sparse(image, invalid_kernel, mode=mode)
def test_bad_inputs(): # Too few dimensions img = cp.ones(10) labels = cp.arange(10) with testing.raises(ValueError): random_walker(img, labels) with testing.raises(ValueError): random_walker(img, labels, multichannel=True) # Too many dimensions np.random.seed(42) img = cp.array(np.random.normal(size=(3, 3, 3, 3, 3))) labels = cp.arange(3**5).reshape(img.shape) with testing.raises(ValueError): random_walker(img, labels) with testing.raises(ValueError): random_walker(img, labels, multichannel=True) # Spacing incorrect length img = cp.array(np.random.normal(size=(10, 10))) labels = cp.zeros((10, 10)) labels[2, 4] = 2 labels[6, 8] = 5 with testing.raises(ValueError): random_walker(img, labels, spacing=cp.array((1, ))) # Invalid mode img = cp.array(np.random.normal(size=(10, 10))) labels = cp.zeros((10, 10)) with testing.raises(ValueError): random_walker(img, labels, mode='bad')
def test_threshold_minimum_failure(): img = cp.zeros((16 * 16), dtype=cp.uint8) with testing.raises(RuntimeError): threshold_minimum(img)
def test_local_even_block_size_error(): img = camerad with testing.raises(ValueError): threshold_local(img, block_size=4)
def test_li_negative_inital_guess(): with testing.raises(ValueError): threshold_li(coinsd, initial_guess=-5)
def test_wrong_dtype(): rnd = cp.random.RandomState(0) img = rnd.normal(size=(256, 256)) with testing.raises(ValueError): u, v = optical_flow_ilk(img, img, dtype='int')
def test_incompatible_shapes(): rnd = cp.random.RandomState(0) I0 = rnd.normal(size=(256, 256)) I1 = rnd.normal(size=(255, 256)) with testing.raises(ValueError): u, v = optical_flow_ilk(I0, I1)