当前位置: 首页>>代码示例>>Python>>正文


Python data.lena函数代码示例

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


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

示例1: test_tv_denoise_2d

 def test_tv_denoise_2d(self):
     """
     Apply the TV denoising algorithm on the lena image provided
     by scipy
     """
     # lena image
     lena = color.rgb2gray(data.lena())[:256, :256]
     # add noise to lena
     lena += 0.5 * lena.std() * np.random.randn(*lena.shape)
     # clip noise so that it does not exceed allowed range for float images.
     lena = np.clip(lena, 0, 1)
     # denoise
     denoised_lena = filter.tv_denoise(lena, weight=60.0)
     # which dtype?
     assert denoised_lena.dtype in [np.float, np.float32, np.float64]
     from scipy import ndimage
     grad = ndimage.morphological_gradient(lena, size=((3, 3)))
     grad_denoised = ndimage.morphological_gradient(
         denoised_lena, size=((3, 3)))
     # test if the total variation has decreased
     assert np.sqrt(
         (grad_denoised ** 2).sum()) < np.sqrt((grad ** 2).sum()) / 2
     denoised_lena_int = filter.tv_denoise(img_as_uint(lena),
                                           weight=60.0, keep_type=True)
     assert denoised_lena_int.dtype is np.dtype('uint16')
开发者ID:amueller,项目名称:scikit-image,代码行数:25,代码来源:test_tv_denoise.py

示例2: test_daisy_normalization

def test_daisy_normalization():
    img = img_as_float(data.lena()[: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)

    assert_raises(ValueError, daisy, img, normalization='does_not_exist')
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:31,代码来源:test_daisy.py

示例3: test_rotated_lena

def test_rotated_lena():
    """
    The harris filter should yield the same results with an image and it's
    rotation.
    """
    im = img_as_float(data.lena().mean(axis=2))
    im_rotated = im.T

    # Moravec
    results = peak_local_max(corner_moravec(im))
    results_rotated = peak_local_max(corner_moravec(im_rotated))
    assert (np.sort(results[:, 0]) == np.sort(results_rotated[:, 1])).all()
    assert (np.sort(results[:, 1]) == np.sort(results_rotated[:, 0])).all()

    # Harris
    results = peak_local_max(corner_harris(im))
    results_rotated = peak_local_max(corner_harris(im_rotated))
    assert (np.sort(results[:, 0]) == np.sort(results_rotated[:, 1])).all()
    assert (np.sort(results[:, 1]) == np.sort(results_rotated[:, 0])).all()

    # Shi-Tomasi
    results = peak_local_max(corner_shi_tomasi(im))
    results_rotated = peak_local_max(corner_shi_tomasi(im_rotated))
    assert (np.sort(results[:, 0]) == np.sort(results_rotated[:, 1])).all()
    assert (np.sort(results[:, 1]) == np.sort(results_rotated[:, 0])).all()
开发者ID:almarklein,项目名称:scikit-image,代码行数:25,代码来源:test_corner.py

示例4: test_fast_homography

def test_fast_homography():
    img = rgb2gray(data.lena()).astype(np.uint8)
    img = img[:, :100]

    theta = np.deg2rad(30)
    scale = 0.5
    tx, ty = 50, 50

    H = np.eye(3)
    S = scale * np.sin(theta)
    C = scale * np.cos(theta)

    H[:2, :2] = [[C, -S], [S, C]]
    H[:2, 2] = [tx, ty]

    tform = ProjectiveTransform(H)
    coords = warp_coords(tform.inverse, (img.shape[0], img.shape[1]))

    for order in range(4):
        for mode in ('constant', 'reflect', 'wrap', 'nearest'):
            p0 = map_coordinates(img, coords, mode=mode, order=order)
            p1 = warp(img, tform, mode=mode, order=order)

            # import matplotlib.pyplot as plt
            # f, (ax0, ax1, ax2, ax3) = plt.subplots(1, 4)
            # ax0.imshow(img)
            # ax1.imshow(p0, cmap=plt.cm.gray)
            # ax2.imshow(p1, cmap=plt.cm.gray)
            # ax3.imshow(np.abs(p0 - p1), cmap=plt.cm.gray)
            # plt.show()

            d = np.mean(np.abs(p0 - p1))
            assert d < 0.001
开发者ID:aeweiwi,项目名称:scikit-image,代码行数:33,代码来源:test_warps.py

示例5: test_theano_overfeat_against_binary

def test_theano_overfeat_against_binary():
    layer_correspondence = dict(
        normal=dict(
            large=[(0, 0, None), (1, 2, None), (2, 3, None), (3, 5, None),
                   (4, 6, None), (5, 9, None), (6, 12, None), (7, 15, None),
                   (8, 18, None), (9, 19, None), (10, 21, None),
                   (11, 23, None), (12, 24, None)],
            small=[(0, 0, None), (1, 2, None), (2, 3, None), (3, 5, None),
                   (4, 6, None), (5, 9, None), (6, 12, None), (7, 15, None),
                   (8, 16, None), (9, 18, None), (10, 20, None), 
                   (11, 21, None)]),
        detailed=dict(
            large=[(i, i, None) for i in range(25)],
            small=[(i, i, None) for i in range(22)]
            )
        )

    rng = np.random.RandomState(42)
    image = (rng.rand(320, 320, 3) * 255).astype(np.uint8)
    from skimage.data import lena
    image = lena()

    for detailed, correspondences in layer_correspondence.items():
        for net_size, correspondence in correspondences.items():
            for theano_layer, binary_layer, cropping in correspondence:
                _check_overfeat_layer(image, theano_layer, binary_layer,
                                      net_size == 'large',
                                      detailed == 'detailed',
                                      cropping=cropping)
开发者ID:Faruk-Ahmed,项目名称:sklearn-theano,代码行数:29,代码来源:test_overfeat.py

示例6: test_lena

def test_lena():

    from skimage import data
    from skimage import color
    from skimage.transform import resize

    in_shape = (200, 200)
    n_imgs = 1

    lena = resize(color.rgb2gray(data.lena()), in_shape).astype(np.float32)
    lena -= lena.min()
    lena /= lena.max()

    imgs = lena.reshape((n_imgs,) + in_shape)

    model = cnnr.models.fg11_ht_l3_1_description
    extractor = cnnr.BatchExtractor(in_shape, model)

    feat_set, _ = extractor.extract(imgs)

    assert feat_set.shape == (n_imgs, 10, 10, 256)

    feat_set.shape = n_imgs, -1
    test_chunk_computed = feat_set[0, 12798:12802]

    test_chunk_expected = np.array([0.03845372, 0.02469639, 0.01009409, 0.02500059], dtype=np.float32)

    assert_allclose(test_chunk_computed, test_chunk_expected, rtol=RTOL, atol=ATOL)
开发者ID:luca-bondi,项目名称:convnet-rfw,代码行数:28,代码来源:test_extractor.py

示例7: test_corner_orientations_lena

def test_corner_orientations_lena():
    img = rgb2gray(data.lena())
    corners = corner_peaks(corner_fast(img, 11, 0.35))
    expected = np.array([-1.9195897 , -3.03159624, -1.05991162, -2.89573739,
                         -2.61607644, 2.98660159])
    actual = corner_orientations(img, corners, octagon(3, 2))
    assert_almost_equal(actual, expected)
开发者ID:AlexG31,项目名称:scikit-image,代码行数:7,代码来源:test_corner.py

示例8: test_fast_homography

def test_fast_homography():
    img = rgb2gray(data.lena()).astype(np.uint8)
    img = img[:, :100]

    theta = np.deg2rad(30)
    scale = 0.5
    tx, ty = 50, 50

    H = np.eye(3)
    S = scale * np.sin(theta)
    C = scale * np.cos(theta)

    H[:2, :2] = [[C, -S], [S, C]]
    H[:2, 2] = [tx, ty]

    for mode in ('constant', 'mirror', 'wrap'):
        p0 = homography(img, H, mode=mode, order=1)
        p1 = fast_homography(img, H, mode=mode)
        p1 = np.round(p1)

        ## import matplotlib.pyplot as plt
        ## f, (ax0, ax1, ax2, ax3) = plt.subplots(1, 4)
        ## ax0.imshow(img)
        ## ax1.imshow(p0, cmap=plt.cm.gray)
        ## ax2.imshow(p1, cmap=plt.cm.gray)
        ## ax3.imshow(np.abs(p0 - p1), cmap=plt.cm.gray)
        ## plt.show()

        d = np.mean(np.abs(p0 - p1))
        assert d < 0.2
开发者ID:NeilYager,项目名称:scikits-image,代码行数:30,代码来源:test_warps.py

示例9: main

def main():
    """Plot example augmentations for Lena and an image loaded from a file."""

    # try on a lena image
    image = data.lena()
    augmenter = ImageAugmenter(image.shape[0], image.shape[1],
                               hflip=True, vflip=True,
                               scale_to_percent=1.3, scale_axis_equally=False,
                               rotation_deg=25, shear_deg=10,
                               translation_x_px=5, translation_y_px=5)

    augmenter.plot_image(image, 100)

    # check loading of images from file and augmenting them
    image = misc.imread("chameleon.png")
    augmenter = ImageAugmenter(image.shape[1], image.shape[0],
                               hflip=True, vflip=True,
                               scale_to_percent=1.3, scale_axis_equally=False,
                               rotation_deg=25, shear_deg=10,
                               translation_x_px=5, translation_y_px=5)

    augmenter.plot_image(image, 50)

    # move the channel from index 2 (3rd position) to index 0 (1st position)
    # so (y, x, rgb) becomes (rgb, y, x)
    # try if it still works
    image = np.rollaxis(image, 2, 0)
    augmenter = ImageAugmenter(image.shape[2], image.shape[1],
                               hflip=True, vflip=True,
                               scale_to_percent=1.3, scale_axis_equally=False,
                               rotation_deg=25, shear_deg=10,
                               translation_x_px=5, translation_y_px=5,
                               channel_is_first_axis=True)
    augmenter.plot_image(image, 50)
开发者ID:aleju,项目名称:ImageAugmenter,代码行数:34,代码来源:CheckPlotImages.py

示例10: test_binary_descriptors_lena_rotation_crosscheck_true

def test_binary_descriptors_lena_rotation_crosscheck_true():
    """Verify matched keypoints and their corresponding masks results between
    lena image and its rotated version with the expected keypoint pairs with
    cross_check enabled."""
    img = data.lena()
    img = rgb2gray(img)
    tform = tf.SimilarityTransform(scale=1, rotation=0.15, translation=(0, 0))
    rotated_img = tf.warp(img, tform)

    extractor = BRIEF(descriptor_size=512)

    keypoints1 = corner_peaks(corner_harris(img), min_distance=5)
    extractor.extract(img, keypoints1)
    descriptors1 = extractor.descriptors

    keypoints2 = corner_peaks(corner_harris(rotated_img), min_distance=5)
    extractor.extract(rotated_img, keypoints2)
    descriptors2 = extractor.descriptors

    matches = match_descriptors(descriptors1, descriptors2, cross_check=True)

    exp_matches1 = np.array([ 0,  1,  2,  4,  6,  7,  9, 10, 11, 12, 13, 15,
                               16, 17, 19, 20, 21, 24, 26, 27, 28, 29, 30, 35,
                               36, 38, 39, 40, 42, 44, 45])
    exp_matches2 = np.array([33,  0, 35,  1,  3,  2,  6,  4,  9, 11, 10,  7,
                                8,  5, 14, 13, 15, 16, 17, 18, 19, 21, 22, 24,
                                23, 26, 27, 25, 28, 29, 30])
    assert_equal(matches[:, 0], exp_matches1)
    assert_equal(matches[:, 1], exp_matches2)
开发者ID:A-0-,项目名称:scikit-image,代码行数:29,代码来源:test_match.py

示例11: lena

def lena(gray=True, small=True):
    im = data.lena()
    if small:
        im = imresize(im, size=(im.shape[0] / 4, im.shape[1] / 4))
    if gray:
        im = im.mean(axis=2)
    return im
开发者ID:NelleV,项目名称:IMANU,代码行数:7,代码来源:data.py

示例12: plot_lena_overlay

def plot_lena_overlay():
    plt.figure()
    logo = ScipyLogo((300, 300), 180)
    logo.plot_snake_curve()
    logo.plot_circle()
    img = data.lena()
    plt.imshow(img)
开发者ID:Rapternmn,项目名称:scikit-image,代码行数:7,代码来源:scipy_logo.py

示例13: test_histogram_of_oriented_gradients

def test_histogram_of_oriented_gradients():
    img = img_as_float(data.lena()[:256, :].mean(axis=2))

    fd = feature.hog(img, orientations=9, pixels_per_cell=(8, 8),
                     cells_per_block=(1, 1))

    assert len(fd) == 9 * (256 // 8) * (512 // 8)
开发者ID:A-0-,项目名称:scikit-image,代码行数:7,代码来源:test_hog.py

示例14: test_keypoints_orb_less_than_desired_no_of_keypoints

def test_keypoints_orb_less_than_desired_no_of_keypoints():
    img = rgb2gray(lena())
    detector_extractor = ORB(n_keypoints=15, fast_n=12,
                             fast_threshold=0.33, downscale=2, n_scales=2)
    detector_extractor.detect(img)

    exp_rows = np.array([  67.,  247.,  269.,  413.,  435.,  230.,  264.,
                          330.,  372.])
    exp_cols = np.array([ 157.,  146.,  111.,   70.,  180.,  136.,  336.,
                          148.,  156.])

    exp_scales = np.array([ 1.,  1.,  1.,  1.,  1.,  2.,  2.,  2.,  2.])

    exp_orientations = np.array([-105.76503839,  -96.28973044,  -53.08162354,
                                 -173.4479964 , -175.64733392, -106.07927215,
                                 -163.40016243,   75.80865813, -154.73195911])

    exp_response = np.array([ 0.13197835,  0.24931321,  0.44351774,
                              0.39063076,  0.96770745,  0.04935129,
                              0.21431068,  0.15826555,  0.42403573])

    assert_almost_equal(exp_rows, detector_extractor.keypoints[:, 0])
    assert_almost_equal(exp_cols, detector_extractor.keypoints[:, 1])
    assert_almost_equal(exp_scales, detector_extractor.scales)
    assert_almost_equal(exp_response, detector_extractor.responses)
    assert_almost_equal(exp_orientations,
                        np.rad2deg(detector_extractor.orientations), 5)

    detector_extractor.detect_and_extract(img)
    assert_almost_equal(exp_rows, detector_extractor.keypoints[:, 0])
    assert_almost_equal(exp_cols, detector_extractor.keypoints[:, 1])
开发者ID:A-0-,项目名称:scikit-image,代码行数:31,代码来源:test_orb.py

示例15: test

def test():
    img = skimage.img_as_float(data.lena())
    img_size = img.shape[:2]

    trans = get_transform(20,15,1.05, 0.02, img_size)
    img_transformed = transform.warp(img, trans)
    obj_func = lambda x: transform_and_compare(img_transformed, img, x)
    x0 = np.array([0,0,1, 0])
    results = optimize.fmin_bfgs(obj_func, x0)

    transform_estimated = get_simple_transform(results) 
    transform_optimal = transform.AffineTransform(np.linalg.inv(trans._matrix))
    params_optimal = np.concatenate([transform_optimal.translation,
                                    transform_optimal.scale[0:1],
                                    [transform_optimal.rotation]])
    img_registered = transform.warp(img_transformed, 
                                    transform_estimated)
    err_original = mean_sq_diff(img_transformed, img)
    err_optimal = transform_and_compare(img_transformed, img, params_optimal) 
    err_actual = transform_and_compare(img_transformed, img, results) 
    err_relative = err_optimal/err_original
    
    print "Params optimal:", params_optimal
    print "Params estimated:", results
    print "Error without registration:", err_original
    print "Error of optimal registration:", err_optimal 
    print "Error of estimated transformation %f (%.2f %% of intial)" % (err_actual,
                                                            err_relative*100.)

    plt.figure()
    plt.subplot(121)
    plt.imshow(img_transformed)
    plt.subplot(122)
    plt.imshow(img_registered)
开发者ID:btel,项目名称:imageregistration,代码行数:34,代码来源:registration.py


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