• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.assert_almost_equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skimage._shared.testing.assert_almost_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_almost_equal函数的具体用法?Python assert_almost_equal怎么用?Python assert_almost_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_almost_equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_fundamental_matrix_forward

def test_fundamental_matrix_forward():
    essential_matrix_tform = EssentialMatrixTransform(
        rotation=np.eye(3), translation=np.array([1, 0, 0]))
    tform = FundamentalMatrixTransform()
    tform.params = essential_matrix_tform.params
    src = np.array([[0, 0], [0, 1], [1, 1]])
    assert_almost_equal(tform(src), [[0, -1, 0], [0, -1, 1], [0, -1, 1]])
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_geometric.py


示例2: test_template

def test_template():
    size = 100
    # Float prefactors ensure that image range is between 0 and 1
    image = np.full((400, 400), 0.5)
    target = 0.1 * (np.tri(size) + np.tri(size)[::-1])
    target_positions = [(50, 50), (200, 200)]
    for x, y in target_positions:
        image[x:x + size, y:y + size] = target
    np.random.seed(1)
    image += 0.1 * np.random.uniform(size=(400, 400))

    result = match_template(image, target)
    delta = 5

    positions = peak_local_max(result, min_distance=delta)

    if len(positions) > 2:
        # Keep the two maximum peaks.
        intensities = result[tuple(positions.T)]
        i_maxsort = np.argsort(intensities)[::-1]
        positions = positions[i_maxsort][:2]

    # Sort so that order matches `target_positions`.
    positions = positions[np.argsort(positions[:, 0])]

    for xy_target, xy in zip(target_positions, positions):
        assert_almost_equal(xy, xy_target)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:27,代码来源:test_template.py


示例3: 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, QtWidgets.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:Cadair,项目名称:scikit-image,代码行数:30,代码来源:test_widgets.py


示例4: test_ellipse_model_predict

def test_ellipse_model_predict():
    model = EllipseModel()
    model.params = (0, 0, 5, 10, 0)
    t = np.arange(0, 2 * np.pi, np.pi / 2)

    xy = np.array(((5, 0), (0, 10), (-5, 0), (0, -10)))
    assert_almost_equal(xy, model.predict_xy(t))
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_fit.py


示例5: test_NRMSE_no_int_overflow

def test_NRMSE_no_int_overflow():
    camf = cam.astype(np.float32)
    cam_noisyf = cam_noisy.astype(np.float32)
    assert_almost_equal(compare_mse(cam, cam_noisy),
                        compare_mse(camf, cam_noisyf))
    assert_almost_equal(compare_nrmse(cam, cam_noisy),
                        compare_nrmse(camf, cam_noisyf))
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_simple_metrics.py


示例6: 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
    with warnings.catch_warnings():
        # We do not want warnings about length 1 dimensions
        warnings.simplefilter("ignore")
        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)]
    with warnings.catch_warnings():
        # We do not want warnings about length 1 dimensions
        warnings.simplefilter("ignore")
        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:Cadair,项目名称:scikit-image,代码行数:35,代码来源:test_unwrap.py


示例7: test_peak_float_out_of_range_dtype

def test_peak_float_out_of_range_dtype():
    im = np.array([10, 100], dtype=np.float16)
    nbins = 10
    frequencies, bin_centers = exposure.histogram(im, nbins=nbins, source_range='dtype')
    assert_almost_equal(np.min(bin_centers), -0.9, 3)
    assert_almost_equal(np.max(bin_centers), 0.9, 3)
    assert_equal(len(bin_centers), 10)
开发者ID:ThomasWalter,项目名称:scikit-image,代码行数:7,代码来源:test_exposure.py


示例8: test_daisy_normalization

def test_daisy_normalization():
    img = img_as_float(data.astronaut()[:64, :64].mean(axis=2))

    descs = daisy(img, normalization='l1')
    for i in range(descs.shape[0]):
        for j in range(descs.shape[1]):
            assert_almost_equal(np.sum(descs[i, j, :]), 1)
    descs_ = daisy(img)
    assert_almost_equal(descs, descs_)

    descs = daisy(img, normalization='l2')
    for i in range(descs.shape[0]):
        for j in range(descs.shape[1]):
            assert_almost_equal(sqrt(np.sum(descs[i, j, :] ** 2)), 1)

    orientations = 8
    descs = daisy(img, orientations=orientations, normalization='daisy')
    desc_dims = descs.shape[2]
    for i in range(descs.shape[0]):
        for j in range(descs.shape[1]):
            for k in range(0, desc_dims, orientations):
                assert_almost_equal(sqrt(np.sum(
                    descs[i, j, k:k + orientations] ** 2)), 1)

    img = np.zeros((50, 50))
    descs = daisy(img, normalization='off')
    for i in range(descs.shape[0]):
        for j in range(descs.shape[1]):
            assert_almost_equal(np.sum(descs[i, j, :]), 0)

    with testing.raises(ValueError):
        daisy(img, normalization='does_not_exist')
开发者ID:Cadair,项目名称:scikit-image,代码行数:32,代码来源:test_daisy.py


示例9: test_ssim_multichannel

def test_ssim_multichannel():
    N = 100
    X = (np.random.rand(N, N) * 255).astype(np.uint8)
    Y = (np.random.rand(N, N) * 255).astype(np.uint8)

    S1 = ssim(X, Y, win_size=3)

    # replicate across three channels.  should get identical value
    Xc = np.tile(X[..., np.newaxis], (1, 1, 3))
    Yc = np.tile(Y[..., np.newaxis], (1, 1, 3))
    S2 = ssim(Xc, Yc, multichannel=True, win_size=3)
    assert_almost_equal(S1, S2)

    # full case should return an image as well
    m, S3 = ssim(Xc, Yc, multichannel=True, full=True)
    assert_equal(S3.shape, Xc.shape)

    # gradient case
    m, grad = ssim(Xc, Yc, multichannel=True, gradient=True)
    assert_equal(grad.shape, Xc.shape)

    # full and gradient case
    m, grad, S3 = ssim(Xc, Yc, multichannel=True, full=True, gradient=True)
    assert_equal(grad.shape, Xc.shape)
    assert_equal(S3.shape, Xc.shape)

    # fail if win_size exceeds any non-channel dimension
    with testing.raises(ValueError):
        ssim(Xc, Yc, win_size=7, multichannel=False)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:29,代码来源:test_structural_similarity.py


示例10: test_all_props_3d

def test_all_props_3d():
    region = regionprops(SAMPLE_3D, INTENSITY_SAMPLE_3D)[0]
    for prop in PROPS:
        try:
            assert_almost_equal(region[prop], getattr(region, PROPS[prop]))
        except (NotImplementedError, TypeError):
            pass
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_regionprops.py


示例11: test_all_props

def test_all_props():
    region = regionprops(SAMPLE, INTENSITY_SAMPLE)[0]
    for prop in PROPS:
        try:
            assert_almost_equal(region[prop], getattr(region, PROPS[prop]))
        except TypeError:  # the `slice` property causes this
            pass
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_regionprops.py


示例12: test_stackcopy

def test_stackcopy():
    layers = 4
    x = np.empty((3, 3, layers))
    y = np.eye(3, 3)
    _stackcopy(x, y)
    for i in range(layers):
        assert_almost_equal(x[..., i], y)
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_warps.py


示例13: test_line_model_nd_estimate

def test_line_model_nd_estimate():
    # generate original data without noise
    model0 = LineModelND()
    model0.params = (np.array([0, 0, 0], dtype='float'),
                     np.array([1, 1, 1], dtype='float')/np.sqrt(3))
    # we scale the unit vector with a factor 10 when generating points on the
    # line in order to compensate for the scale of the random noise
    data0 = (model0.params[0] +
             10 * np.arange(-100, 100)[..., np.newaxis] * model0.params[1])

    # add gaussian noise to data
    random_state = np.random.RandomState(1234)
    data = data0 + random_state.normal(size=data0.shape)

    # estimate parameters of noisy data
    model_est = LineModelND()
    model_est.estimate(data)
    # assert_almost_equal(model_est.residuals(data0), np.zeros(len(data)), 1)

    # test whether estimated parameters are correct
    # we use the following geometric property: two aligned vectors have
    # a cross-product equal to zero
    # test if direction vectors are aligned
    assert_almost_equal(np.linalg.norm(np.cross(model0.params[1],
                                                model_est.params[1])), 0, 1)
    # test if origins are aligned with the direction
    a = model_est.params[0] - model0.params[0]
    if np.linalg.norm(a) > 0:
        a /= np.linalg.norm(a)
    assert_almost_equal(np.linalg.norm(np.cross(model0.params[1], a)), 0, 1)
开发者ID:Cadair,项目名称:scikit-image,代码行数:30,代码来源:test_fit.py


示例14: test_gaussian_mssim_vs_IPOL

def test_gaussian_mssim_vs_IPOL():
    # Tests vs. imdiff result from the following IPOL article and code:
    # https://www.ipol.im/pub/art/2011/g_lmii/
    mssim_IPOL = 0.327309966087341
    mssim = ssim(cam, cam_noisy, gaussian_weights=True,
                 use_sample_covariance=False)
    assert_almost_equal(mssim, mssim_IPOL, decimal=3)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_structural_similarity.py


示例15: test_rgb2yiq_conversion

 def test_rgb2yiq_conversion(self):
     rgb = img_as_float(self.img_rgb)[::16, ::16]
     yiq = rgb2yiq(rgb).reshape(-1, 3)
     gt = np.array([colorsys.rgb_to_yiq(pt[0], pt[1], pt[2])
                    for pt in rgb.reshape(-1, 3)]
                   )
     assert_almost_equal(yiq, gt, decimal=2)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_colorconv.py


示例16: test_resize2d

def test_resize2d():
    x = np.zeros((5, 5), dtype=np.double)
    x[1, 1] = 1
    resized = resize(x, (10, 10), order=0, anti_aliasing=False,
                     mode='constant')
    ref = np.zeros((10, 10))
    ref[2:4, 2:4] = 1
    assert_almost_equal(resized, ref)
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_warps.py


示例17: test_circle_model_predict

def test_circle_model_predict():
    model = CircleModel()
    r = 5
    model.params = (0, 0, r)
    t = np.arange(0, 2 * np.pi, np.pi / 2)

    xy = np.array(((5, 0), (0, 5), (-5, 0), (0, -5)))
    assert_almost_equal(xy, model.predict_xy(t))
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_fit.py


示例18: test_rgba2rgb_conversion

 def test_rgba2rgb_conversion(self):
     rgba = self.img_rgba
     rgb = rgba2rgb(rgba)
     expected = np.array([[[1, 1, 1],
                           [0, 0.5, 1],
                           [0.5, 0.75, 1]]]).astype(np.float)
     self.assertEqual(rgb.shape, expected.shape)
     assert_almost_equal(rgb, expected)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:8,代码来源:test_colorconv.py


示例19: test_hsv2rgb_conversion

 def test_hsv2rgb_conversion(self):
     rgb = self.img_rgb.astype("float32")[::16, ::16]
     # create HSV image with colorsys
     hsv = np.array([colorsys.rgb_to_hsv(pt[0], pt[1], pt[2])
                     for pt in rgb.reshape(-1, 3)]).reshape(rgb.shape)
     # convert back to RGB and compare with original.
     # relative precision for RGB -> HSV roundtrip is about 1e-6
     assert_almost_equal(rgb, hsv2rgb(hsv), decimal=4)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:8,代码来源:test_colorconv.py


示例20: test_rgb2hsv_conversion

 def test_rgb2hsv_conversion(self):
     rgb = img_as_float(self.img_rgb)[::16, ::16]
     hsv = rgb2hsv(rgb).reshape(-1, 3)
     # ground truth from colorsys
     gt = np.array([colorsys.rgb_to_hsv(pt[0], pt[1], pt[2])
                    for pt in rgb.reshape(-1, 3)]
                   )
     assert_almost_equal(hsv, gt)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:8,代码来源:test_colorconv.py



注:本文中的skimage._shared.testing.assert_almost_equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.assert_array_almost_equal函数代码示例发布时间:2022-05-27
下一篇:
Python testing.assert_allclose函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap