本文整理汇总了Python中skimage._shared.testing.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_dtype.py
示例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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:34,代码来源:test_denoise.py
示例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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:25,代码来源:test_random_noise.py
示例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")
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_chan_vese.py
示例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])
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_block.py
示例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))
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_regionprops.py
示例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),))
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_random_shapes.py
示例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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:32,代码来源:test_polygon.py
示例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')
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_simple_metrics.py
示例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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_geometric.py
示例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)))
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_pil.py
示例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')
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_warps.py
示例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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_morphsnakes.py
示例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')
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_reconstruction.py
示例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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_active_contour_model.py
示例16: test_unwrap_1d
def test_unwrap_1d():
image = np.linspace(0, 10 * np.pi, 100)
check_unwrap(image)
# Masked arrays are not allowed in 1D
with testing.raises(ValueError):
check_unwrap(image, True)
# wrap_around is not allowed in 1D
with testing.raises(ValueError):
unwrap_phase(image, True, seed=0)
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_unwrap.py
示例17: test_invalid_input
def test_invalid_input():
with testing.raises(ValueError):
unwrap_phase(np.zeros([]))
with testing.raises(ValueError):
unwrap_phase(np.zeros((1, 1, 1, 1)))
with testing.raises(ValueError):
unwrap_phase(np.zeros((1, 1)), 3 * [False])
with testing.raises(ValueError):
unwrap_phase(np.zeros((1, 1)), 'False')
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_unwrap.py
示例18: test_prepare_grayscale_input_2D
def test_prepare_grayscale_input_2D():
with testing.raises(ValueError):
_prepare_grayscale_input_2D(np.zeros((3, 3, 3)))
with testing.raises(ValueError):
_prepare_grayscale_input_2D(np.zeros((3, 1)))
with testing.raises(ValueError):
_prepare_grayscale_input_2D(np.zeros((3, 1, 1)))
img = _prepare_grayscale_input_2D(np.zeros((3, 3)))
img = _prepare_grayscale_input_2D(np.zeros((3, 3, 1)))
img = _prepare_grayscale_input_2D(np.zeros((1, 3, 3)))
开发者ID:Cadair,项目名称:scikit-image,代码行数:10,代码来源:test_util.py
示例19: test_invalid_selem
def test_invalid_selem():
seed = np.ones((5, 5))
mask = np.ones((5, 5))
with testing.raises(ValueError):
reconstruction(seed, mask,
selem=np.ones((4, 4)))
with testing.raises(ValueError):
reconstruction(seed, mask,
selem=np.ones((3, 4)))
reconstruction(seed, mask, selem=np.ones((3, 3)))
开发者ID:Cadair,项目名称:scikit-image,代码行数:10,代码来源:test_reconstruction.py
示例20: test_negative_sigma
def test_negative_sigma():
a = np.zeros((3, 3))
a[1, 1] = 1.
with testing.raises(ValueError):
gaussian(a, sigma=-1.0)
with testing.raises(ValueError):
gaussian(a, sigma=[-1.0, 1.0])
with testing.raises(ValueError):
gaussian(a,
sigma=np.asarray([-1.0, 1.0]))
开发者ID:TheArindham,项目名称:scikit-image,代码行数:10,代码来源:test_gaussian.py
注:本文中的skimage._shared.testing.raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论