本文整理汇总了Python中skimage._shared.testing.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raises函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_float_out_of_range
def test_float_out_of_range():
too_high = np.array([2], dtype=np.float32)
with testing.raises(ValueError):
img_as_int(too_high)
too_low = np.array([-2], dtype=np.float32)
with testing.raises(ValueError):
img_as_int(too_low)
示例2: test_wavelet_denoising_levels
def test_wavelet_denoising_levels():
rstate = np.random.RandomState(1234)
ndim = 2
N = 256
wavelet = 'db1'
# Generate a very simple test image
img = 0.2*np.ones((N, )*ndim)
img[[slice(5, 13), ] * ndim] = 0.8
sigma = 0.1
noisy = img + sigma * rstate.randn(*(img.shape))
noisy = np.clip(noisy, 0, 1)
denoised = restoration.denoise_wavelet(noisy, wavelet=wavelet)
denoised_1 = restoration.denoise_wavelet(noisy, wavelet=wavelet,
wavelet_levels=1)
psnr_noisy = compare_psnr(img, noisy)
psnr_denoised = compare_psnr(img, denoised)
psnr_denoised_1 = compare_psnr(img, denoised_1)
# multi-level case should outperform single level case
assert_(psnr_denoised > psnr_denoised_1 > psnr_noisy)
# invalid number of wavelet levels results in a ValueError
max_level = pywt.dwt_max_level(np.min(img.shape),
pywt.Wavelet(wavelet).dec_len)
with testing.raises(ValueError):
restoration.denoise_wavelet(
noisy,
wavelet=wavelet, wavelet_levels=max_level+1)
with testing.raises(ValueError):
restoration.denoise_wavelet(
noisy,
wavelet=wavelet, wavelet_levels=-1)
示例3: test_localvar
def test_localvar():
seed = 42
data = np.zeros((128, 128)) + 0.5
local_vars = np.zeros((128, 128)) + 0.001
local_vars[:64, 64:] = 0.1
local_vars[64:, :64] = 0.25
local_vars[64:, 64:] = 0.45
data_gaussian = random_noise(data, mode='localvar', seed=seed,
local_vars=local_vars, clip=False)
assert 0. < data_gaussian[:64, :64].var() < 0.002
assert 0.095 < data_gaussian[:64, 64:].var() < 0.105
assert 0.245 < data_gaussian[64:, :64].var() < 0.255
assert 0.445 < data_gaussian[64:, 64:].var() < 0.455
# Ensure local variance bounds checking works properly
bad_local_vars = np.zeros_like(data)
with testing.raises(ValueError):
random_noise(data, mode='localvar', seed=seed,
local_vars=bad_local_vars)
bad_local_vars += 0.1
bad_local_vars[0, 0] = -1
with testing.raises(ValueError):
random_noise(data, mode='localvar', seed=seed,
local_vars=bad_local_vars)
示例4: test_chan_vese_incorrect_level_set
def test_chan_vese_incorrect_level_set():
img = np.zeros((10, 10))
ls = np.zeros((10, 9))
with testing.raises(ValueError):
chan_vese(img, mu=0.0, init_level_set=ls)
with testing.raises(ValueError):
chan_vese(img, mu=0.0, init_level_set="a")
示例5: test_invalid_block_size
def test_invalid_block_size():
image = np.arange(4 * 6).reshape(4, 6)
with testing.raises(ValueError):
block_reduce(image, [1, 2, 3])
with testing.raises(ValueError):
block_reduce(image, [1, 0.5])
示例6: test_dtype
def test_dtype():
regionprops(np.zeros((10, 10), dtype=np.int))
regionprops(np.zeros((10, 10), dtype=np.uint))
with testing.raises(TypeError):
regionprops(np.zeros((10, 10), dtype=np.float))
with testing.raises(TypeError):
regionprops(np.zeros((10, 10), dtype=np.double))
示例7: test_throws_when_intensity_range_out_of_range
def test_throws_when_intensity_range_out_of_range():
with testing.raises(ValueError):
random_shapes((1000, 1234), max_shapes=1, multichannel=False,
intensity_range=(0, 256))
with testing.raises(ValueError):
random_shapes((2, 2), max_shapes=1,
intensity_range=((-1, 255),))
示例8: test_subdivide_polygon
def test_subdivide_polygon():
new_square1 = square
new_square2 = square[:-1]
new_square3 = square[:-1]
# test iterative subdvision
for _ in range(10):
square1, square2, square3 = new_square1, new_square2, new_square3
# test different B-Spline degrees
for degree in range(1, 7):
mask_len = len(_SUBDIVISION_MASKS[degree][0])
# test circular
new_square1 = subdivide_polygon(square1, degree)
assert_array_equal(new_square1[-1], new_square1[0])
assert_equal(new_square1.shape[0],
2 * square1.shape[0] - 1)
# test non-circular
new_square2 = subdivide_polygon(square2, degree)
assert_equal(new_square2.shape[0],
2 * (square2.shape[0] - mask_len + 1))
# test non-circular, preserve_ends
new_square3 = subdivide_polygon(square3, degree, True)
assert_equal(new_square3[0], square3[0])
assert_equal(new_square3[-1], square3[-1])
assert_equal(new_square3.shape[0],
2 * (square3.shape[0] - mask_len + 2))
# not supported B-Spline degree
with testing.raises(ValueError):
subdivide_polygon(square, 0)
with testing.raises(ValueError):
subdivide_polygon(square, 8)
示例9: test_NRMSE_errors
def test_NRMSE_errors():
x = np.ones(4)
# shape mismatch
with testing.raises(ValueError):
compare_nrmse(x[:-1], x)
# invalid normalization name
with testing.raises(ValueError):
compare_nrmse(x, x, 'foo')
示例10: test_geometric_tform
def test_geometric_tform():
tform = GeometricTransform()
with testing.raises(NotImplementedError):
tform(0)
with testing.raises(NotImplementedError):
tform.inverse(0)
with testing.raises(NotImplementedError):
tform.__add__(0)
示例11: test_imsave_incorrect_dimension
def test_imsave_incorrect_dimension():
with temporary_file(suffix='.png') as fname:
with testing.raises(ValueError):
with expected_warnings([fname + ' is a low contrast image']):
imsave(fname, np.zeros((2, 3, 3, 1)))
with testing.raises(ValueError):
with expected_warnings([fname + ' is a low contrast image']):
imsave(fname, np.zeros((2, 3, 2)))
示例12: test_rescale_invalid_scale
def test_rescale_invalid_scale():
x = np.zeros((10, 10, 3))
with testing.raises(ValueError):
rescale(x, (2, 2),
multichannel=False, anti_aliasing=False, mode='constant')
with testing.raises(ValueError):
rescale(x, (2, 2, 2),
multichannel=True, anti_aliasing=False, mode='constant')
示例13: test_morphsnakes_incorrect_ndim
def test_morphsnakes_incorrect_ndim():
img = np.zeros((4, 4, 4, 4))
ls = np.zeros((4, 4, 4, 4))
with testing.raises(ValueError):
morphological_chan_vese(img, iterations=1, init_level_set=ls)
with testing.raises(ValueError):
morphological_geodesic_active_contour(img, iterations=1,
init_level_set=ls)
示例14: test_invalid_seed
def test_invalid_seed():
seed = np.ones((5, 5))
mask = np.ones((5, 5))
with testing.raises(ValueError):
reconstruction(seed * 2, mask,
method='dilation')
with testing.raises(ValueError):
reconstruction(seed * 0.5, mask,
method='erosion')
示例15: test_bad_input
def test_bad_input():
img = np.zeros((10, 10))
x = np.linspace(5, 424, 100)
y = np.linspace(136, 50, 100)
init = np.array([x, y]).T
with testing.raises(ValueError):
active_contour(img, init, bc='wrong')
with testing.raises(ValueError):
active_contour(img, init, max_iterations=-15)