本文整理汇总了Python中skimage._shared._warnings.expected_warnings函数的典型用法代码示例。如果您正苦于以下问题:Python expected_warnings函数的具体用法?Python expected_warnings怎么用?Python expected_warnings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expected_warnings函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_wrap_around
def check_wrap_around(ndim, axis):
# create a ramp, but with the last pixel along axis equalling the first
elements = 100
ramp = np.linspace(0, 12 * np.pi, elements)
ramp[-1] = ramp[0]
image = ramp.reshape(tuple([elements if n == axis else 1
for n in range(ndim)]))
image_wrapped = np.angle(np.exp(1j * image))
index_first = tuple([0] * ndim)
index_last = tuple([-1 if n == axis else 0 for n in range(ndim)])
# unwrap the image without wrap around
# We do not want warnings about length 1 dimensions
with expected_warnings([r'Image has a length 1 dimension|\A\Z']):
image_unwrap_no_wrap_around = unwrap_phase(image_wrapped, seed=0)
print('endpoints without wrap_around:',
image_unwrap_no_wrap_around[index_first],
image_unwrap_no_wrap_around[index_last])
# without wrap around, the endpoints of the image should differ
assert_(abs(image_unwrap_no_wrap_around[index_first] -
image_unwrap_no_wrap_around[index_last]) > np.pi)
# unwrap the image with wrap around
wrap_around = [n == axis for n in range(ndim)]
# We do not want warnings about length 1 dimensions
with expected_warnings([r'Image has a length 1 dimension.|\A\Z']):
image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around,
seed=0)
print('endpoints with wrap_around:',
image_unwrap_wrap_around[index_first],
image_unwrap_wrap_around[index_last])
# with wrap around, the endpoints of the image should be equal
assert_almost_equal(image_unwrap_wrap_around[index_first],
image_unwrap_wrap_around[index_last])
开发者ID:TheArindham,项目名称:scikit-image,代码行数:33,代码来源:test_unwrap.py
示例2: test_neg_inf
def test_neg_inf():
expected_costs = np.where(a == 1, np.inf, 0)
expected_path = [(1, 6),
(1, 5),
(1, 4),
(1, 3),
(1, 2),
(2, 1),
(3, 1),
(4, 1),
(5, 1),
(6, 1)]
test_neg = np.where(a == 1, -1, 0)
test_inf = np.where(a == 1, np.inf, 0)
with expected_warnings(['Upgrading NumPy' + warning_optional]):
m = mcp.MCP(test_neg, fully_connected=True)
costs, traceback = m.find_costs([(1, 6)])
return_path = m.traceback((6, 1))
assert_array_equal(costs, expected_costs)
assert_array_equal(return_path, expected_path)
with expected_warnings(['Upgrading NumPy' + warning_optional]):
m = mcp.MCP(test_inf, fully_connected=True)
costs, traceback = m.find_costs([(1, 6)])
return_path = m.traceback((6, 1))
assert_array_equal(costs, expected_costs)
assert_array_equal(return_path, expected_path)
开发者ID:AbdealiJK,项目名称:scikit-image,代码行数:26,代码来源:test_mcp.py
示例3: color_check
def color_check(plugin, fmt="png"):
"""Check roundtrip behavior for color images.
All major input types should be handled as ubytes and read
back correctly.
"""
img = img_as_ubyte(data.chelsea())
r1 = roundtrip(img, plugin, fmt)
testing.assert_allclose(img, r1)
img2 = img > 128
r2 = roundtrip(img2, plugin, fmt)
testing.assert_allclose(img2.astype(np.uint8), r2)
img3 = img_as_float(img)
with expected_warnings(["precision loss|unclosed file"]):
r3 = roundtrip(img3, plugin, fmt)
testing.assert_allclose(r3, img)
with expected_warnings(["precision loss"]):
img4 = img_as_int(img)
if fmt.lower() in (("tif", "tiff")):
img4 -= 100
with expected_warnings(["sign loss"]):
r4 = roundtrip(img4, plugin, fmt)
testing.assert_allclose(r4, img4)
else:
with expected_warnings(["sign loss|precision loss|unclosed file"]):
r4 = roundtrip(img4, plugin, fmt)
testing.assert_allclose(r4, img_as_ubyte(img4))
img5 = img_as_uint(img)
with expected_warnings(["precision loss|unclosed file"]):
r5 = roundtrip(img5, plugin, fmt)
testing.assert_allclose(r5, img)
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:35,代码来源:testing.py
示例4: test_save_buttons
def test_save_buttons():
viewer = get_image_viewer()
sv = SaveButtons()
viewer.plugins[0] += sv
import tempfile
fid, filename = tempfile.mkstemp(suffix='.png')
os.close(fid)
timer = QtCore.QTimer()
timer.singleShot(100, QtGui.QApplication.quit)
# exercise the button clicks
sv.save_stack.click()
sv.save_file.click()
# call the save functions directly
sv.save_to_stack()
with expected_warnings(['precision loss']):
sv.save_to_file(filename)
img = data.imread(filename)
with expected_warnings(['precision loss']):
assert_almost_equal(img, img_as_uint(viewer.image))
img = io.pop()
assert_almost_equal(img, viewer.image)
os.remove(filename)
开发者ID:AbdealiJK,项目名称:scikit-image,代码行数:30,代码来源:test_widgets.py
示例5: test_wavelet_threshold
def test_wavelet_threshold():
rstate = np.random.RandomState(1234)
img = astro_gray
sigma = 0.1
noisy = img + sigma * rstate.randn(*(img.shape))
noisy = np.clip(noisy, 0, 1)
# employ a single, user-specified threshold instead of BayesShrink sigmas
with expected_warnings([PYWAVELET_ND_INDEXING_WARNING]):
denoised = _wavelet_threshold(noisy, wavelet='db1', method=None,
threshold=sigma)
psnr_noisy = compare_psnr(img, noisy)
psnr_denoised = compare_psnr(img, denoised)
assert_(psnr_denoised > psnr_noisy)
# either method or threshold must be defined
with testing.raises(ValueError):
_wavelet_threshold(noisy, wavelet='db1', method=None, threshold=None)
# warns if a threshold is provided in a case where it would be ignored
with expected_warnings(["Thresholding method ",
PYWAVELET_ND_INDEXING_WARNING]):
_wavelet_threshold(noisy, wavelet='db1', method='BayesShrink',
threshold=sigma)
开发者ID:ThomasWalter,项目名称:scikit-image,代码行数:25,代码来源:test_denoise.py
示例6: _test_image
def _test_image(self, image):
with expected_warnings(['precision loss']):
result_opening = grey.opening(image, self.disk)
testing.assert_equal(result_opening, self.expected_opening)
with expected_warnings(['precision loss']):
result_closing = grey.closing(image, self.disk)
testing.assert_equal(result_closing, self.expected_closing)
开发者ID:haohao200609,项目名称:Hybrid,代码行数:8,代码来源:test_grey.py
示例7: 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
示例8: test_deprecated_params_attributes
def test_deprecated_params_attributes():
for t in ('projective', 'affine', 'similarity'):
tform = estimate_transform(t, SRC, DST)
with expected_warnings(['`_matrix`.*deprecated']):
assert_equal(tform._matrix, tform.params)
tform = estimate_transform('polynomial', SRC, DST, order=3)
with expected_warnings(['`_params`.*deprecated']):
assert_equal(tform._params, tform.params)
开发者ID:haohao200609,项目名称:Hybrid,代码行数:9,代码来源:test_geometric.py
示例9: test_euler_number
def test_euler_number():
with expected_warnings(['`background`|CObject type']):
en = regionprops(SAMPLE)[0].euler_number
assert en == 0
SAMPLE_mod = SAMPLE.copy()
SAMPLE_mod[7, -3] = 0
with expected_warnings(['`background`|CObject type']):
en = regionprops(SAMPLE_mod)[0].euler_number
assert en == -1
开发者ID:MartinSavc,项目名称:scikit-image,代码行数:10,代码来源:test_regionprops.py
示例10: test_resize3d_keep
def test_resize3d_keep():
# keep 3rd dimension
x = np.zeros((5, 5, 3), dtype=np.double)
x[1, 1, :] = 1
with expected_warnings(['The default mode']):
resized = resize(x, (10, 10), order=0)
ref = np.zeros((10, 10, 3))
ref[2:4, 2:4, :] = 1
assert_almost_equal(resized, ref)
with expected_warnings(['The default mode']):
resized = resize(x, (10, 10, 3), order=0)
assert_almost_equal(resized, ref)
开发者ID:noahstier,项目名称:scikit-image,代码行数:12,代码来源:test_warps.py
示例11: test_3d_fallback_black_tophat
def test_3d_fallback_black_tophat():
image = np.ones((7, 7, 7), dtype=bool)
image[2, 2:4, 2:4] = 0
image[3, 2:5, 2:5] = 0
image[4, 3:5, 3:5] = 0
with expected_warnings(['operator.*deprecated|\A\Z']):
new_image = grey.black_tophat(image)
footprint = ndi.generate_binary_structure(3,1)
with expected_warnings(['operator.*deprecated|\A\Z']):
image_expected = ndi.black_tophat(image,footprint=footprint)
testing.assert_array_equal(new_image, image_expected)
开发者ID:AbdealiJK,项目名称:scikit-image,代码行数:12,代码来源:test_grey.py
示例12: test_warp_clip
def test_warp_clip():
x = np.zeros((5, 5), dtype=np.double)
x[2, 2] = 1
with expected_warnings(['The default mode', 'The default multichannel']):
outx = rescale(x, 3, order=3, clip=False)
assert outx.min() < 0
with expected_warnings(['The default mode', 'The default multichannel']):
outx = rescale(x, 3, order=3, clip=True)
assert_almost_equal(outx.min(), 0)
assert_almost_equal(outx.max(), 1)
开发者ID:andreydung,项目名称:scikit-image,代码行数:12,代码来源:test_warps.py
示例13: test_spacing_1
def test_spacing_1():
n = 30
lx, ly, lz = n, n, n
data, _ = make_3d_syntheticdata(lx, ly, lz)
# Rescale `data` along Y axis
# `resize` is not yet 3D capable, so this must be done by looping in 2D.
data_aniso = np.zeros((n, n * 2, n))
for i, yz in enumerate(data):
data_aniso[i, :, :] = resize(yz, (n * 2, n),
mode='constant',
anti_aliasing=False)
# Generate new labels
small_l = int(lx // 5)
labels_aniso = np.zeros_like(data_aniso)
labels_aniso[lx // 5, ly // 5, lz // 5] = 1
labels_aniso[lx // 2 + small_l // 4,
ly - small_l // 2,
lz // 2 - small_l // 4] = 2
# Test with `spacing` kwarg
# First, anisotropic along Y
with expected_warnings(['"cg" mode' + '|' + SCIPY_RANK_WARNING,
NUMPY_MATRIX_WARNING]):
labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg',
spacing=(1., 2., 1.))
assert (labels_aniso[13:17, 26:34, 13:17] == 2).all()
# Rescale `data` along X axis
# `resize` is not yet 3D capable, so this must be done by looping in 2D.
data_aniso = np.zeros((n, n * 2, n))
for i in range(data.shape[1]):
data_aniso[i, :, :] = resize(data[:, 1, :], (n * 2, n),
mode='constant',
anti_aliasing=False)
# Generate new labels
small_l = int(lx // 5)
labels_aniso2 = np.zeros_like(data_aniso)
labels_aniso2[lx // 5, ly // 5, lz // 5] = 1
labels_aniso2[lx - small_l // 2,
ly // 2 + small_l // 4,
lz // 2 - small_l // 4] = 2
# Anisotropic along X
with expected_warnings(['"cg" mode' + '|' + SCIPY_RANK_WARNING,
NUMPY_MATRIX_WARNING]):
labels_aniso2 = random_walker(data_aniso,
labels_aniso2,
mode='cg', spacing=(2., 1., 1.))
assert (labels_aniso2[26:34, 13:17, 13:17] == 2).all()
开发者ID:anntzer,项目名称:scikit-image,代码行数:52,代码来源:test_random_walker.py
示例14: test_multispectral_2d
def test_multispectral_2d():
lx, ly = 70, 100
data, labels = make_2d_syntheticdata(lx, ly)
data = data[..., np.newaxis].repeat(2, axis=-1) # Expect identical output
with expected_warnings(['"cg" mode' + '|' + SCIPY_EXPECTED]):
multi_labels = random_walker(data, labels, mode='cg',
multichannel=True)
assert data[..., 0].shape == labels.shape
with expected_warnings(['"cg" mode' + '|' + SCIPY_EXPECTED]):
single_labels = random_walker(data[..., 0], labels, mode='cg')
assert (multi_labels.reshape(labels.shape)[25:45, 40:60] == 2).all()
assert data[..., 0].shape == labels.shape
return data, multi_labels, single_labels, labels
开发者ID:ameya005,项目名称:scikit-image,代码行数:13,代码来源:test_random_walker.py
示例15: test_3d_fallback_white_tophat
def test_3d_fallback_white_tophat():
image = np.zeros((7, 7, 7), dtype=bool)
image[2, 2:4, 2:4] = 1
image[3, 2:5, 2:5] = 1
image[4, 3:5, 3:5] = 1
with expected_warnings([r'operator.*deprecated|\A\Z']):
new_image = grey.white_tophat(image)
footprint = ndi.generate_binary_structure(3, 1)
with expected_warnings([r'operator.*deprecated|\A\Z']):
image_expected = ndi.white_tophat(
image.view(dtype=np.uint8), footprint=footprint)
assert_array_equal(new_image, image_expected)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:13,代码来源:test_grey.py
示例16: test_rescale_multichannel_defaults
def test_rescale_multichannel_defaults():
# ensure multichannel=None matches the previous default behaviour
# 2D: multichannel should default to False
x = np.zeros((8, 3), dtype=np.double)
with expected_warnings(['The default mode', 'The default multichannel']):
scaled = rescale(x, 2, order=0)
assert_equal(scaled.shape, (16, 6))
# 3D: multichannel should default to True
x = np.zeros((8, 8, 3), dtype=np.double)
with expected_warnings(['The default mode', 'The default multichannel']):
scaled = rescale(x, 2, order=0,)
assert_equal(scaled.shape, (16, 16, 3))
开发者ID:andreydung,项目名称:scikit-image,代码行数:14,代码来源:test_warps.py
示例17: test_wavelet_denoising
def test_wavelet_denoising():
rstate = np.random.RandomState(1234)
# version with one odd-sized dimension
astro_gray_odd = astro_gray[:, :-1]
astro_odd = astro[:, :-1]
for img, multichannel, convert2ycbcr in [(astro_gray, False, False),
(astro_gray_odd, False, False),
(astro_odd, True, False),
(astro_odd, True, True)]:
sigma = 0.1
noisy = img + sigma * rstate.randn(*(img.shape))
noisy = np.clip(noisy, 0, 1)
# Verify that SNR is improved when true sigma is used
with expected_warnings([PYWAVELET_ND_INDEXING_WARNING]):
denoised = restoration.denoise_wavelet(noisy, sigma=sigma,
multichannel=multichannel,
convert2ycbcr=convert2ycbcr)
psnr_noisy = compare_psnr(img, noisy)
psnr_denoised = compare_psnr(img, denoised)
assert_(psnr_denoised > psnr_noisy)
# Verify that SNR is improved with internally estimated sigma
with expected_warnings([PYWAVELET_ND_INDEXING_WARNING]):
denoised = restoration.denoise_wavelet(noisy,
multichannel=multichannel,
convert2ycbcr=convert2ycbcr)
psnr_noisy = compare_psnr(img, noisy)
psnr_denoised = compare_psnr(img, denoised)
assert_(psnr_denoised > psnr_noisy)
# SNR is improved less with 1 wavelet level than with the default.
denoised_1 = restoration.denoise_wavelet(noisy,
multichannel=multichannel,
wavelet_levels=1,
convert2ycbcr=convert2ycbcr)
psnr_denoised_1 = compare_psnr(img, denoised_1)
assert_(psnr_denoised > psnr_denoised_1)
assert_(psnr_denoised_1 > psnr_noisy)
# Test changing noise_std (higher threshold, so less energy in signal)
with expected_warnings([PYWAVELET_ND_INDEXING_WARNING]):
res1 = restoration.denoise_wavelet(noisy, sigma=2 * sigma,
multichannel=multichannel)
with expected_warnings([PYWAVELET_ND_INDEXING_WARNING]):
res2 = restoration.denoise_wavelet(noisy, sigma=sigma,
multichannel=multichannel)
assert_(np.sum(res1**2) <= np.sum(res2**2))
开发者ID:ThomasWalter,项目名称:scikit-image,代码行数:50,代码来源:test_denoise.py
示例18: test_resize3d_keep
def test_resize3d_keep():
# keep 3rd dimension
x = np.zeros((5, 5, 3), dtype=np.double)
x[1, 1, :] = 1
with expected_warnings(['The default mode']):
resized = resize(x, (10, 10), order=0)
with pytest.raises(ValueError):
# output_shape too short
resize(x, (10, ), order=0)
ref = np.zeros((10, 10, 3))
ref[2:4, 2:4, :] = 1
assert_almost_equal(resized, ref)
with expected_warnings(['The default mode']):
resized = resize(x, (10, 10, 3), order=0)
assert_almost_equal(resized, ref)
开发者ID:andreydung,项目名称:scikit-image,代码行数:15,代码来源:test_warps.py
示例19: test_2d_cg
def test_2d_cg():
lx = 70
ly = 100
data, labels = make_2d_syntheticdata(lx, ly)
with expected_warnings(['"cg" mode' + '|' + SCIPY_EXPECTED]):
labels_cg = random_walker(data, labels, beta=90, mode='cg')
assert (labels_cg[25:45, 40:60] == 2).all()
assert data.shape == labels.shape
with expected_warnings(['"cg" mode' + '|' + SCIPY_EXPECTED]):
full_prob = random_walker(data, labels, beta=90, mode='cg',
return_full_prob=True)
assert (full_prob[1, 25:45, 40:60] >=
full_prob[0, 25:45, 40:60]).all()
assert data.shape == labels.shape
return data, labels_cg
开发者ID:ameya005,项目名称:scikit-image,代码行数:15,代码来源:test_random_walker.py
示例20: test_multispectral_3d
def test_multispectral_3d():
n = 30
lx, ly, lz = n, n, n
data, labels = make_3d_syntheticdata(lx, ly, lz)
data = data[..., np.newaxis].repeat(2, axis=-1) # Expect identical output
with expected_warnings(['"cg" mode']):
multi_labels = random_walker(data, labels, mode='cg',
multichannel=True)
assert data[..., 0].shape == labels.shape
with expected_warnings(['"cg" mode']):
single_labels = random_walker(data[..., 0], labels, mode='cg')
assert (multi_labels.reshape(labels.shape)[13:17, 13:17, 13:17] == 2).all()
assert (single_labels.reshape(labels.shape)[13:17, 13:17, 13:17] == 2).all()
assert data[..., 0].shape == labels.shape
return data, multi_labels, single_labels, labels
开发者ID:AbdealiJK,项目名称:scikit-image,代码行数:15,代码来源:test_random_walker.py
注:本文中的skimage._shared._warnings.expected_warnings函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论