Example #1
1
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')
Example #2
0
 def setUpClass(cls):
     cls.tmpdir = tempfile.mkdtemp()
     cls.db_name = tempfile.mkdtemp(dir=cls.tmpdir)
     cls.db = _.DbCreator(cls.db_name, 'lmdb')
     _handle, cls.lena_path = tempfile.mkstemp(dir=cls.tmpdir, suffix='.jpg')
     with open(cls.lena_path, 'w') as outfile:
         PIL.Image.fromarray(data.lena()).save(outfile, format='JPEG', quality=100)
Example #3
0
File: data.py Project: NelleV/IMANU
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
Example #4
0
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
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
def main():
    src_rgb_img = data.lena()
    #src_rgb_img = io.imread('Child_input.png')

    src_Lab_img = color.rgb2lab(src_rgb_img)
    src_Lab_img_L = src_Lab_img[:, :, 0]

    src_Lab_img_a = src_Lab_img[:, :, 1]
    src_Lab_img_b = src_Lab_img[:, :, 2]

    #down_sampling with scale = 0.5
    scale = 0.25
    src = bicubic2d(src_Lab_img_L, scale) * 2.55

    #up_sampling with scale = 2.0 to source image by different method
    dst_me = bicubic2d(src, 4.0)
    dst_other = imresize(
        src, 4.0, interp='bicubic')  #this method result is int and in [0,255]

    #evalue different with PSNR MY result is better
    print psnr(dst_me / 2.55, src_Lab_img_L)
    print psnr(dst_other / 2.55, src_Lab_img_L)

    plt.imshow(dst_me, interpolation="none")
    plt.show()
Example #10
0
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)
Example #11
0
def plot_lena_overlay():
    plt.figure()
    logo = ScipyLogo((300, 300), 180)
    logo.plot_snake_curve()
    logo.plot_circle()
    img = data.lena()
    plt.imshow(img)
Example #12
0
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])
Example #13
0
def plot_lena_overlay():
    plt.figure()
    logo = ScipyLogo((300, 300), 180)
    logo.plot_snake_curve()
    logo.plot_circle()
    img = data.lena()
    plt.imshow(img)
Example #14
0
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)
Example #15
0
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)
Example #16
0
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)
Example #17
0
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()
Example #18
0
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
Example #19
0
    def MR_boudnary_extraction(self, img=None):
        if img == None:
            img = cv2.cvtColor(lena(), cv2.COLOR_RGB2BGR)
        lab_img = self._MR_saliency__MR_readimg(img)
        mark_color = (1, 0, 0)
        labels = self._MR_saliency__MR_superpixel(lab_img)

        up_img = lab_img.copy()
        up_ids = sp.unique(labels[0, :]).astype(int)
        up_mask = sp.zeros(labels.shape).astype(bool)
        for i in up_ids:
            up_mask = sp.logical_or(up_mask, labels == i)
        up_img[up_mask] = mark_color
        up_img = mark_boundaries(up_img, labels)

        right_img = lab_img.copy()
        right_ids = sp.unique(labels[:, labels.shape[1] - 1]).astype(int)
        right_mask = sp.zeros(labels.shape).astype(bool)
        for i in right_ids:
            right_mask = sp.logical_or(right_mask, labels == i)
        right_img[right_mask] = mark_color
        right_img = mark_boundaries(right_img, labels)

        low_img = lab_img.copy()
        low_ids = sp.unique(labels[labels.shape[0] - 1, :]).astype(int)
        low_mask = sp.zeros(labels.shape).astype(bool)
        for i in low_ids:
            low_mask = sp.logical_or(low_mask, labels == i)
        low_img[low_mask] = mark_color
        low_img = mark_boundaries(low_img, labels)

        left_img = lab_img.copy()
        left_ids = sp.unique(labels[:, 0]).astype(int)
        left_mask = sp.zeros(labels.shape).astype(bool)
        for i in left_ids:
            left_mask = sp.logical_or(left_mask, labels == i)
        left_img[left_mask] = mark_color
        left_img = mark_boundaries(left_img, labels)

        plt.subplot(2, 2, 1)
        plt.axis('off')
        plt.title('up')
        plt.imshow(up_img)

        plt.subplot(2, 2, 2)
        plt.axis('off')
        plt.title('bottom')
        plt.imshow(low_img)

        plt.subplot(2, 2, 3)
        plt.axis('off')
        plt.title('left')
        plt.imshow(left_img)

        plt.subplot(2, 2, 4)
        plt.axis('off')
        plt.title('right')
        plt.imshow(right_img)

        plt.show()
Example #20
0
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
Example #21
0
 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')
Example #22
0
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()
Example #23
0
def test_match_keypoints_brief_lena_rotation():
    """Verify matched keypoints result between lena image and its rotated
    version with the expected keypoint pairs."""
    img = data.lena()
    img = rgb2gray(img)
    img.shape
    tform = tf.SimilarityTransform(scale=1, rotation=0.10, translation=(0, 0))
    rotated_img = tf.warp(img, tform)

    keypoints1 = corner_peaks(corner_harris(img), min_distance=5)
    descriptors1, keypoints1 = brief(img, keypoints1, descriptor_size=512)

    keypoints2 = corner_peaks(corner_harris(rotated_img), min_distance=5)
    descriptors2, keypoints2 = brief(rotated_img,
                                     keypoints2,
                                     descriptor_size=512)

    matched_keypoints = match_keypoints_brief(keypoints1,
                                              descriptors1,
                                              keypoints2,
                                              descriptors2,
                                              threshold=0.07)

    expected = np.array([[[263, 272], [234, 298]], [[271, 120], [258, 146]],
                         [[323, 164], [305, 195]], [[414, 70], [405, 111]],
                         [[435, 181], [415, 223]], [[454, 176], [435, 221]]])

    assert_array_equal(matched_keypoints, expected)
Example #24
0
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)
Example #25
0
def test_corner_fast_lena():
    img = rgb2gray(data.lena())
    expected = np.array([[67, 157], [204, 261], [247, 146], [269, 111],
                         [318, 158], [386, 73], [413, 70], [435, 180],
                         [455, 177], [461, 160]])
    actual = corner_peaks(corner_fast(img, 12, 0.3))
    assert_array_equal(actual, expected)
Example #26
0
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')
Example #27
0
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, clip=False)

    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)
Example #28
0
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])
    def test_original_images(self):
        images = self.manager.original_images()
        n_images = sum(1 for _ in images)
        self.assertEqual(n_images, 1)

        lena = data.lena()
        for image in images:
            self.assertEqual(image.shape, lena.shape)
Example #30
0
    def MR_boundary_saliency(self,img=None):
        if img == None:
            img = cv2.cvtColor(lena(),cv2.COLOR_RGB2BGR)
        lab_img = self._MR_saliency__MR_readimg(img)
    
        labels = self._MR_saliency__MR_superpixel(lab_img)
        
        up,right,low,left = self._MR_saliency__MR_boundary_indictor(labels)
        aff = self._MR_saliency__MR_affinity_matrix(lab_img,labels)

        up_sal = 1- self._MR_saliency__MR_saliency(aff,up)
        up_img = self._MR_saliency__MR_fill_superpixel_with_saliency(labels,up_sal)
        up_img = up_img.astype(np.uint8)
    
        right_sal = 1-self._MR_saliency__MR_saliency(aff,right)
        right_img =  self._MR_saliency__MR_fill_superpixel_with_saliency(labels,right_sal)
        right_img = right_img.astype(np.uint8)

        low_sal = 1-self._MR_saliency__MR_saliency(aff,low)
        low_img = self._MR_saliency__MR_fill_superpixel_with_saliency(labels,low_sal)
        low_img = low_img.astype(np.uint8)
    
        left_sal = 1-self._MR_saliency__MR_saliency(aff,left)
        left_img = self._MR_saliency__MR_fill_superpixel_with_saliency(labels,left_sal)
        left_img = left_img.astype(np.uint8)
        

        plt.subplot(3,2,1)
        plt.title('orginal')
        plt.axis('off')
        plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
        
        plt.subplot(3,2,2)
        plt.title('up')
        plt.axis('off')
        plt.imshow(up_img,'gray')
        
        plt.subplot(3,2,3)
        plt.title('right')
        plt.axis('off')
        plt.imshow(right_img,'gray')
        
        plt.subplot(3,2,4)
        plt.title('low')
        plt.axis('off')
        plt.imshow(low_img,'gray')
        
        plt.subplot(3,2,5)
        plt.title('left')
        plt.axis('off')
        plt.imshow(left_img,'gray')
        
        plt.subplot(3,2,6)
        plt.title('integrated')
        plt.axis('off')
        saliency_map = MR_debuger().saliency(img).astype(np.uint8)
        plt.imshow( saliency_map,'gray')
        plt.show()
Example #31
0
def m1():
    #加载字典
    mat = scipy.io.loadmat('./Dictionary/dictionary.mat')
    Dl_dict = np.asarray(mat['Dl'], dtype='float64')
    Dh_dict = np.asarray(mat['Dh'], dtype='float64')

    #提取出L通道进行计算其他通道使用Bicubic进行计算
    #src_rgb_img = io.imread('./Data/Child_input.png')
    src_rgb_img = data.lena()
    src = src_rgb_img[:src_rgb_img.shape[0] -
                      src_rgb_img.shape[0] % 3, :src_rgb_img.shape[1] -
                      src_rgb_img.shape[0] % 3, :]
    src_rgb_img = src
    #需要变称散的倍数才能处理
    #src_rgb_img = bicubic_2d.bicubic2d(src,1/3.0)
    src_rgb_img = bicubic_2d.bicubic2d(src_rgb_img, 1 / 3.0)
    src_rgb_img = src_rgb_img[:src_rgb_img.shape[0] -
                              src_rgb_img.shape[0] % 3, :src_rgb_img.shape[1] -
                              src_rgb_img.shape[0] % 3, :]
    #print src_rgb_img.shape

    src_Lab_img = color.rgb2lab(src_rgb_img)
    src_Lab_img_L = src_Lab_img[:, :, 0]
    src_Lab_img_a = src_Lab_img[:, :, 1]
    src_Lab_img_b = src_Lab_img[:, :, 2]

    #不同的L通道来源
    #dst_Lab_img_L = readSR()
    #m = dst_Lab_img_L<0
    #dst_Lab_img_L[m] = 0
    #print np.max(dst_Lab_img_L),np.min(dst_Lab_img_L)
    #dst_Lab_img_L = SR(src_Lab_img_L,Dh_dict,Dl_dict)
    dst_Lab_img_L = imresize(src_Lab_img_L, 3.0, 'bicubic')
    #dst_Lab_img_L= dst_Lab_img_L/255.0*(np.max(src_Lab_img_L)-np.min(src_Lab_img_L))+np.min(src_Lab_img_L)

    dst_Lab_img_a = imresize(src_Lab_img_a, 3.0, 'bicubic')
    dst_Lab_img_a = dst_Lab_img_a / 255.0 * (
        np.max(src_Lab_img_a) - np.min(src_Lab_img_a)) + np.min(src_Lab_img_a)

    dst_Lab_img_b = imresize(src_Lab_img_b, 3.0, 'bicubic')
    dst_Lab_img_b = dst_Lab_img_b / 255.0 * (
        np.max(src_Lab_img_b) - np.min(src_Lab_img_b)) + np.min(src_Lab_img_b)

    img_lab = np.zeros((dst_Lab_img_L.shape[0], dst_Lab_img_L.shape[1], 3))
    img_lab[:, :, 0] = dst_Lab_img_L
    img_lab[:, :, 1] = dst_Lab_img_a
    img_lab[:, :, 2] = dst_Lab_img_b

    dst = color.lab2rgb(img_lab)
    #src = src[:dst.shape[0],:dst.shape[1]]

    #print np.mean(dst[10:-15,10:-15]*255-src[10:-15,10:-15])

    #print psnr(dst[10:-15,10:-15]*255,src[10:-15,10:-15])
    plt.imshow(dst, interpolation="none")

    plt.show()
Example #32
0
    def MR_showsuperpixel(self,img=None):
        if img == None:
            img = cv2.cvtColor(lena(),cv2.COLOR_RGB2BGR)
        img = self._MR_saliency__MR_readimg(img)
        labels = self._MR_saliency__MR_superpixel(img)

        plt.axis('off')
        plt.imshow(mark_boundaries(img,labels))
        plt.show()
Example #33
0
def test_is_rgb():
    color = data.lena()
    gray = data.camera()

    assert is_rgb(color)
    assert not is_gray(color)

    assert is_gray(gray)
    assert not is_gray(color)
def test_is_rgb():
    color = data.lena()
    gray = data.camera()

    assert is_rgb(color)
    assert not is_gray(color)

    assert is_gray(gray)
    assert not is_gray(color)
Example #35
0
 def test_rotated_lena(self):
     """
     The harris filter should yield the same results with an image and it's
     rotation.
     """
     im = img_as_float(data.lena().mean(axis=2))
     results = harris(im)
     im_rotated = im.T
     results_rotated = harris(im_rotated)
     assert (results[:, 0] == results_rotated[:, 1]).all()
Example #36
0
 def test_tv_denoise_float_result_range(self):
     # lena image
     lena = color.rgb2gray(data.lena())[:256, :256]
     int_lena = np.multiply(lena, 255).astype(np.uint8)
     assert np.max(int_lena) > 1
     denoised_int_lena = filter.tv_denoise(int_lena, weight=60.0)
     # test if the value range of output float data is within [0.0:1.0]
     assert denoised_int_lena.dtype == np.float
     assert np.max(denoised_int_lena) <= 1.0
     assert np.min(denoised_int_lena) >= 0.0
 def test_tv_denoise_float_result_range(self):
     # lena image
     lena = color.rgb2gray(data.lena())[:256, :256]
     int_lena = np.multiply(lena, 255).astype(np.uint8)
     assert np.max(int_lena) > 1       
     denoised_int_lena = filter.tv_denoise(int_lena, weight=60.0)
     # test if the value range of output float data is within [0.0:1.0]
     assert denoised_int_lena.dtype == np.float
     assert np.max(denoised_int_lena) <= 1.0
     assert np.min(denoised_int_lena) >= 0.0        
Example #38
0
def test_num_peaks():
    """For a bunch of different values of num_peaks, check that
    peak_local_max returns exactly the right amount of peaks. Test
    is run on Lena in order to produce a sufficient number of corners"""

    lena_corners = corner_harris(rgb2gray(data.lena()))

    for i in range(20):
        n = np.random.random_integers(20)
        results = peak_local_max(lena_corners, num_peaks=n)
        assert (results.shape[0] == n)
Example #39
0
def test_num_peaks():
    """For a bunch of different values of num_peaks, check that
    peak_local_max returns exactly the right amount of peaks. Test
    is run on Lena in order to produce a sufficient number of corners"""

    lena_corners = corner_harris(data.lena())

    for i in range(20):
        n = np.random.random_integers(20)
        results = peak_local_max(lena_corners, num_peaks=n)
        assert (results.shape[0] == n)
Example #40
0
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))
    results = harris(im)
    im_rotated = im.T
    results_rotated = 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()
Example #41
0
def test_warp_identity():
    lena = img_as_float(rgb2gray(data.lena()))
    assert len(lena.shape) == 2
    assert np.allclose(lena, warp(lena, AffineTransform(rotation=0)))
    assert not np.allclose(lena, warp(lena, AffineTransform(rotation=0.1)))
    rgb_lena = np.transpose(np.asarray([lena, np.zeros_like(lena), lena]),
                            (1, 2, 0))
    warped_rgb_lena = warp(rgb_lena, AffineTransform(rotation=0.1))
    assert np.allclose(rgb_lena, warp(rgb_lena, AffineTransform(rotation=0)))
    assert not np.allclose(rgb_lena, warped_rgb_lena)
    # assert no cross-talk between bands
    assert np.all(0 == warped_rgb_lena[:, :, 1])
Example #42
0
def m3():
    #加载字典
    mat = scipy.io.loadmat('./Dictionary/dictionary.mat')
    Dl_dict = np.asarray(mat['Dl'], dtype='float64')
    Dh_dict = np.asarray(mat['Dh'], dtype='float64')

    #提取出L通道进行计算其他通道使用Bicubic进行计算
    src = data.lena()
    src_yCrCb = colormanage.rgb2ycbcr(src)

    src_Ycbcr_img_Y = bicubic_2d.bicubic2d(src_yCrCb[:, :, 0], 1 / 3.0)
    src_Ycbcr_img_Cb = bicubic_2d.bicubic2d(src_yCrCb[:, :, 1], 1 / 3.0)
    src_Ycbcr_img_Cr = bicubic_2d.bicubic2d(src_yCrCb[:, :, 2], 1 / 3.0)

    src_Ycbcr_img_Y = src_Ycbcr_img_Y[:src_Ycbcr_img_Y.shape[0] -
                                      src_Ycbcr_img_Y.shape[0] %
                                      3, :src_Ycbcr_img_Y.shape[1] -
                                      src_Ycbcr_img_Y.shape[0] % 3]
    src_Ycbcr_img_Cb = src_Ycbcr_img_Cb[:src_Ycbcr_img_Cb.shape[0] -
                                        src_Ycbcr_img_Cb.shape[0] %
                                        3, :src_Ycbcr_img_Cb.shape[1] -
                                        src_Ycbcr_img_Cb.shape[0] % 3]
    src_Ycbcr_img_Cr = src_Ycbcr_img_Cr[:src_Ycbcr_img_Cr.shape[0] -
                                        src_Ycbcr_img_Cr.shape[0] %
                                        3, :src_Ycbcr_img_Cr.shape[1] -
                                        src_Ycbcr_img_Cr.shape[0] % 3]

    #不同的L通道来源
    #dst_Lab_img_L = readSR()
    #dst_Lab_img_L = imresize(src_Lab_img_L,3.0,'bicubic')/2.55
    dst_YCbCr_img_Y = SR(src_Ycbcr_img_Y, Dh_dict, Dl_dict)

    dst_YCbCr_img_Cb = bicubic_2d.bicubic2d(src_Ycbcr_img_Cb, 3.0)

    dst_YCbCr_img_Cr = bicubic_2d.bicubic2d(src_Ycbcr_img_Cr, 3.0)

    img_YCbCr = np.zeros(
        (dst_YCbCr_img_Y.shape[0], dst_YCbCr_img_Y.shape[1], 3))
    img_YCbCr[:, :, 0] = dst_YCbCr_img_Y
    img_YCbCr[:, :, 1] = dst_YCbCr_img_Cb
    img_YCbCr[:, :, 2] = dst_YCbCr_img_Cr

    dst = colormanage.ycbcr2rgb(img_YCbCr)
    src = src[:dst.shape[0], :dst.shape[1]]

    print psnr(dst[10:-15, 10:-15, 1], src[10:-15, 10:-15, 1])

    print np.mean((dst[10:-15, 10:-15] - src[10:-15, 10:-15])**2)
    print np.mean(np.abs(dst[10:-15, 10:-15] * 255 - src[10:-15, 10:-15]))
    print psnr(dst[10:-15, 10:-15], src[10:-15, 10:-15])
    plt.imshow(dst, interpolation="none")

    plt.show()
Example #43
0
def test_adapthist_grayscale():
    """Test a grayscale float image
    """
    img = skimage.img_as_float(data.lena())
    img = rgb2gray(img)
    img = np.dstack((img, img, img))
    adapted = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.01, nbins=128)
    assert_almost_equal = np.testing.assert_almost_equal
    assert img.shape == adapted.shape
    assert_almost_equal(peak_snr(img, adapted), 97.531, 3)
    assert_almost_equal(norm_brightness_err(img, adapted), 0.0313, 3)
    return data, adapted
Example #44
0
def main():
    """Plot example augmentations for Lena and an image loaded from a file."""

    # try on a lena image
    print('Plotting float lena, preserve range')
    image = data.lena().astype(float)
    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,
                               preserve_range=True)
    augmenter.plot_image(image, 10)

    print('Plotting chameleon')
    # 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 / 255.0, 50)

    print('Plotting chameleon with channel_is_first_axis=True')
    # 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)
Example #45
0
def test_adapthist_grayscale():
    '''Test a grayscale float image
    '''
    img = skimage.img_as_float(data.lena())
    img = rgb2gray(img)
    img = np.dstack((img, img, img))
    adapted = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.01,
                        nbins=128)
    assert_almost_equal = np.testing.assert_almost_equal
    assert img.shape == adapted.shape
    assert peak_snr(img, adapted) > 95.0
    assert norm_brightness_err(img, adapted) < 0.05
    return data, adapted
Example #46
0
def test_collection_viewer():

    img = data.lena()
    img_collection = tuple(pyramid_gaussian(img))

    view = CollectionViewer(img_collection)
    make_key_event(48)

    view.update_index('', 2),
    assert_equal(view.image, img_collection[2])
    view.keyPressEvent(make_key_event(53))
    assert_equal(view.image, img_collection[5])
    view._format_coord(10, 10)
Example #47
0
def test_adapthist_color():
    '''Test an RGB color uint16 image
    '''
    img = skimage.img_as_uint(data.lena())
    adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
    assert_almost_equal = np.testing.assert_almost_equal
    assert adapted.min() == 0
    assert adapted.max() == 1.0
    assert img.shape == adapted.shape
    full_scale = skimage.exposure.rescale_intensity(img)
    assert_almost_equal(peak_snr(full_scale, adapted), 102.940, 3)
    assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.0110, 3)
    return data, adapted
Example #48
0
def test_adapthist_color():
    '''Test an RGB color uint16 image
    '''
    img = skimage.img_as_uint(data.lena())
    adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
    assert_almost_equal = np.testing.assert_almost_equal
    assert adapted.min() == 0
    assert adapted.max() == 1.0
    assert img.shape == adapted.shape
    full_scale = skimage.exposure.rescale_intensity(img)
    assert peak_snr(img, adapted) > 95.0
    assert norm_brightness_err(img, adapted) < 0.05
    return data, adapted
Example #49
0
def test_main():
    src_rgb_img = data.lena()

    src_YCrCb_img = rgb2ycbcr(src_rgb_img)
    p = ycbcr2rgb(src_YCrCb_img)

    c =np.asarray(p,dtype='uint8')

    plt.imshow(c)
    print src_rgb_img.dtype,src_rgb_img.shape,np.max(src_rgb_img),np.min(src_rgb_img)
    print c.dtype,c.shape,np.mean((c-src_rgb_img)**2),np.max(c),np.min(c)

    plt.show()
Example #50
0
def test_collection_viewer():

    img = data.lena()
    img_collection = tuple(pyramid_gaussian(img))

    view = CollectionViewer(img_collection)
    make_key_event(48)

    view.update_index('', 2),
    assert_equal(view.image, img_collection[2])
    view.keyPressEvent(make_key_event(53))
    assert_equal(view.image, img_collection[5])
    view._format_coord(10, 10)
Example #51
0
def test_adapthist_alpha():
    """Test an RGBA color image
    """
    img = skimage.img_as_float(data.lena())
    alpha = np.ones((img.shape[0], img.shape[1]), dtype=float)
    img = np.dstack((img, alpha))
    adapted = exposure.equalize_adapthist(img)
    assert adapted.shape != img.shape
    img = img[:, :, :3]
    full_scale = skimage.exposure.rescale_intensity(img)
    assert img.shape == adapted.shape
    assert_almost_equal = np.testing.assert_almost_equal
    assert_almost_equal(peak_snr(full_scale, adapted), 106.86, 2)
    assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.0509, 3)
Example #52
0
def test_descs_shape():
    img = img_as_float(data.lena()[:256, :256].mean(axis=2))
    radius = 20
    step = 8
    descs = daisy(img, radius=radius, step=step)
    assert (descs.shape[0] == ceil((img.shape[0] - radius * 2) / float(step)))
    assert (descs.shape[1] == ceil((img.shape[1] - radius * 2) / float(step)))

    img = img[:-1, :-2]
    radius = 5
    step = 3
    descs = daisy(img, radius=radius, step=step)
    assert (descs.shape[0] == ceil((img.shape[0] - radius * 2) / float(step)))
    assert (descs.shape[1] == ceil((img.shape[1] - radius * 2) / float(step)))
Example #53
0
def test_adapthist_alpha():
    """Test an RGBA color image
    """
    img = skimage.img_as_float(data.lena())
    alpha = np.ones((img.shape[0], img.shape[1]), dtype=float)
    img = np.dstack((img, alpha))
    adapted = exposure.equalize_adapthist(img)
    assert adapted.shape != img.shape
    img = img[:, :, :3]
    full_scale = skimage.exposure.rescale_intensity(img)
    assert img.shape == adapted.shape
    assert_almost_equal = np.testing.assert_almost_equal
    assert_almost_equal(peak_snr(full_scale, adapted), 106.86, 2)
    assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.0509, 3)
Example #54
0
def test_descs_shape():
    img = img_as_float(data.lena()[:256, :256].mean(axis=2))
    radius = 20
    step = 8
    descs = daisy(img, radius=radius, step=step)
    assert(descs.shape[0] == ceil((img.shape[0] - radius * 2) / float(step)))
    assert(descs.shape[1] == ceil((img.shape[1] - radius * 2) / float(step)))

    img = img[:-1, :-2]
    radius = 5
    step = 3
    descs = daisy(img, radius=radius, step=step)
    assert(descs.shape[0] == ceil((img.shape[0] - radius * 2) / float(step)))
    assert(descs.shape[1] == ceil((img.shape[1] - radius * 2) / float(step)))
Example #55
0
def test_corner_fast_lena():
    img = rgb2gray(data.lena())
    expected = np.array([[ 67, 157],
                         [204, 261],
                         [247, 146],
                         [269, 111],
                         [318, 158],
                         [386,  73],
                         [413,  70],
                         [435, 180],
                         [455, 177],
                         [461, 160]])
    actual = corner_peaks(corner_fast(img, 12, 0.3))
    assert_array_equal(actual, expected)
Example #56
0
def test_daisy_desc_dims():
    img = img_as_float(data.lena()[:128, :128].mean(axis=2))
    rings = 2
    histograms = 4
    orientations = 3
    descs = daisy(img, rings=rings, histograms=histograms,
                  orientations=orientations)
    assert(descs.shape[2] == (rings * histograms + 1) * orientations)

    rings = 4
    histograms = 5
    orientations = 13
    descs = daisy(img, rings=rings, histograms=histograms,
                  orientations=orientations)
    assert(descs.shape[2] == (rings * histograms + 1) * orientations)