def test_threshold_local_generic(self): ref = np.array([[1., 7., 16., 29., 37.], [5., 14., 23., 30., 30.], [13., 24., 30., 29., 21.], [25., 29., 28., 19., 10.], [34., 31., 23., 10., 4.]]) unchanged = threshold_local(self.image, 1, method='generic', param=sum) out = threshold_local(self.image, 3, method='generic', param=sum) assert np.allclose(unchanged.compute(), self.image.compute()) assert np.allclose(out.compute(), ref)
def test_threshold_local_generic(self): ref = cupy.array([[1., 7., 16., 29., 37.], [5., 14., 23., 30., 30.], [13., 24., 30., 29., 21.], [25., 29., 28., 19., 10.], [34., 31., 23., 10., 4.]]) my_sum = cupy.ReductionKernel('T x', 'T out', 'x', 'a + b', 'out = a', '0', 'my_sum') unchanged = threshold_local(self.image, 1, method='generic', param=my_sum) # noqa: E501 out = threshold_local(self.image, 3, method='generic', param=my_sum) assert cupy.allclose(unchanged.compute(), self.image.compute()) assert cupy.allclose(out.compute(), ref)
def test_threshold_local_gaussian(self, block_size): ref = np.array([[False, False, False, False, True], [False, False, True, False, True], [False, False, True, True, False], [False, True, True, False, False], [True, True, False, False, False]]) out = threshold_local(self.image, block_size, method='gaussian') cupy.testing.assert_array_equal(ref, (self.image > out).compute()) out = threshold_local(self.image, block_size, method='gaussian', param=1. / 3.) cupy.testing.assert_array_equal(ref, (self.image > out).compute())
def test_threshold_local_median(self, block_size): ref = cupy.array([[False, False, False, False, True], [False, False, True, False, False], [False, False, True, False, False], [False, False, True, True, False], [False, True, False, False, False]]) out = threshold_local(self.image, block_size, method='median') cupy.testing.assert_array_equal(ref, (self.image > out).compute())
def test_threshold_local_mean(self, block_size): ref = np.array([[False, False, False, False, True], [False, False, True, False, True], [False, False, True, True, False], [False, True, True, False, False], [True, True, False, False, False]]) out = threshold_local(self.image, block_size, method='mean') assert_equal(ref, (self.image > out).compute())
def test_threshold_local_generic_invalid(self): expected_error_message = "Must include a valid function to use as " "the 'param' keyword argument." with pytest.raises(ValueError) as e: threshold_local(self.image, 3, method='generic', param='sum') assert e == expected_error_message
def test_invalid_threshold_method(self): with pytest.raises(ValueError): threshold_local(self.image, 3, method='invalid')
def test_nan_blocksize(self, method, block_size, error_type): with pytest.raises(error_type): threshold_local(self.image, block_size, method=method)