コード例 #1
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
コード例 #2
0
ファイル: tp1.py プロジェクト: NelleV/ROVAR
def stitchRL(image2, image3, points23):
    """
    Stitch image1 to image2, with points points
    """
    s = image2.shape[1]
    image2b = np.zeros((image2.shape[0], image2.shape[1] + 500))
    image2b[:, :image2.shape[1]] = image2
    image2 = image2b
    image3b = np.zeros((image3.shape[0], image3.shape[1] + 500))
    image3b[:, :image3.shape[1]] = image3
    image3 = image3b

    #points23[:, 0] += 500
    #points23[:, 2] += 500

    H2 = calculate_homography(points23)

    Hr = H2.copy()
    # Hr[0, 2] = 0
    # Hr[1, 2] = 0
    image3H = transform.homography(image3, H2)
#    image2Hr = np.zeros((image2.shape[0], 1500))
#    image2Hr[:image2.shape[0], :image2.shape[1]] = image2
#    image2Hr = transform.homography(image2Hr, Ht)
#    em = image2Hr.copy()
#    em[:image1.shape[0],:image1.shape[1]] = image1H
    em = image2 + image3H
    em[:,:s] = image2[:, :s]
    return em
コード例 #3
0
def test_homography():
    x = np.arange(9, dtype=np.uint8).reshape((3, 3)) + 1
    theta = -np.pi / 2
    M = np.array([[np.cos(theta), -np.sin(theta), 0],
                  [np.sin(theta), np.cos(theta), 2], [0, 0, 1]])
    x90 = homography(x, M, order=1)
    assert_array_almost_equal(x90, np.rot90(x))
コード例 #4
0
ファイル: test_warps.py プロジェクト: NeilYager/scikits-image
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
コード例 #5
0
ファイル: tp1.py プロジェクト: NelleV/ROVAR
def stitchLR(image1, image2, points):
    """
    Stitch image1 to image2, with points points
    """
    # image 2 is base image. ie, we need to translate image1
    image1b = np.zeros((image1.shape[0], image1.shape[1] + 500))
    image1b[:, 500:] = image1
    image1 = image1b
    image2b = np.zeros((image2.shape[0], image2.shape[1] + 500))
    image2b[:, 500:] = image2
    image2 = image2b

    points[:, 1] += 500
    points[:, 3] += 500

    H2 = calculate_homography(points)

    Hr = H2.copy()
    # Hr[0, 2] = 0
    # Hr[1, 2] = 0
    image1H = transform.homography(image1, H2)
#    image2Hr = np.zeros((image2.shape[0], 1500))
#    image2Hr[:image2.shape[0], :image2.shape[1]] = image2
#    image2Hr = transform.homography(image2Hr, Ht)
#    em = image2Hr.copy()
#    em[:image1.shape[0],:image1.shape[1]] = image1H
    em = image1H + image2
    em[:, 500:] = image2[:, 500:]
    return em
コード例 #6
0
ファイル: test_project.py プロジェクト: Teva/scikits.image
def test_homography():
    x = np.arange(9, dtype=np.uint8).reshape((3, 3)) + 1
    theta = -np.pi/2
    M = np.array([[np.cos(theta),-np.sin(theta),0],
                  [np.sin(theta), np.cos(theta),2],
                  [0,             0,            1]])
    x90 = homography(x, M, order=1)
    assert_array_almost_equal(x90, np.rot90(x))
コード例 #7
0
ファイル: test_warps.py プロジェクト: NeilYager/scikits-image
def test_homography():
    x = np.zeros((5, 5), dtype=np.uint8)
    x[1, 1] = 255
    x = img_as_float(x)
    theta = -np.pi/2
    M = np.array([[np.cos(theta),-np.sin(theta),0],
                  [np.sin(theta), np.cos(theta),4],
                  [0,             0,            1]])
    x90 = homography(x, M, order=1)
    assert_array_almost_equal(x90, np.rot90(x))
コード例 #8
0
def random_rotate(image3D):
    theta = np.deg2rad(10)
    tx = 0
    ty = 0

    S, C = np.sin(theta), np.cos(theta)

    # Rotation matrix, angle theta, translation tx, ty
    H = np.array([[C, -S, tx], [S, C, ty], [0, 0, 1]])

    # Translation matrix to shift the image center to the origin
    r, c = img.shape
    T = np.array([[1, 0, -c / 2.], [0, 1, -r / 2.], [0, 0, 1]])

    # Skew, for perspective
    S = np.array([[1, 0, 0], [0, 1.3, 0], [0, 1e-3, 1]])

    img_rot = transform.homography(img, H)
    img_rot_center_skew = transform.homography(
        img, S.dot(np.linalg.inv(T).dot(H).dot(T)))
    return image3D
コード例 #9
0
from skimage import io, transform

s = 0.7

img = io.imread('scikits_image_logo.png')
h, w, c = img.shape

print "\nScaling down logo by %.1fx..." % s

img = transform.homography(img, [[s, 0, 0], [0, s, 0], [0, 0, 1]],
                           output_shape=(int(h * s), int(w * s), 4),
                           order=3)

io.imsave('scikits_image_logo_small.png', img)
コード例 #10
0
def test_homography_basic():
    homography(np.random.random((25, 25)), np.eye(3))
コード例 #11
0
ファイル: unwarp.py プロジェクト: tuxkp/ay250
import skimage
from skimage import io as sio
from skimage import transform as tf
from skimage import data, color

img = data.camera()

theta = np.deg2rad(30)
c = np.cos(theta)
s = np.sin(theta)
a = 0.4
b = 0.4

H = np.array([[a * c, -b * s, 130], [a * s, b * c, 20], [1e-4, -5e-4, 1]])

img_tf = tf.homography(img, H)

plt.subplot(121)
plt.grid()
plt.axis('image')
plt.xlim(0, X_OUT)
plt.ylim(0, Y_OUT)
ax = plt.gca()
ax.invert_yaxis()

plt.subplot(122)
plt.imshow(img_tf, cmap=plt.cm.gray, interpolation='nearest')

plt.suptitle(
    'Dewarping\nSelect 4 points on the left grid, then 4 in the right '
    'image.')
コード例 #12
0
from skimage import io, transform

s = 0.7

img = io.imread('scikits_image_logo.png')
h, w, c = img.shape

print "\nScaling down logo by %.1fx..." % s

img = transform.homography(img, [[s, 0, 0],
                                 [0, s, 0],
                                 [0, 0, 1]],
                           output_shape=(int(h*s), int(w*s), 4),
                           order=3)

io.imsave('scikits_image_logo_small.png', img)
コード例 #13
0
ファイル: unwarp.py プロジェクト: 5n1p/python-seminar
from skimage import data, color

img = data.camera()

theta = np.deg2rad(30)
c = np.cos(theta)
s = np.sin(theta)
a = 0.4
b = 0.4


H = np.array([[a*c, -b*s,   130],
              [a*s,  b*c,   20],
              [1e-4, -5e-4, 1]])

img_tf = tf.homography(img, H)

plt.subplot(121)
plt.grid()
plt.axis('image')
plt.xlim(0, X_OUT)
plt.ylim(0, Y_OUT)
ax = plt.gca()
ax.invert_yaxis()

plt.subplot(122)
plt.imshow(img_tf, cmap=plt.cm.gray, interpolation='nearest')

plt.suptitle('Dewarping\nSelect 4 points on the left grid, then 4 in the right '
             'image.')
コード例 #14
0
theta = np.deg2rad(10)
tx = 0
ty = 0

S, C = np.sin(theta), np.cos(theta)

# Rotation matrix, angle theta, translation tx, ty
H = np.array([[C, -S, tx],
              [S,  C, ty],
              [0,  0, 1]])

# Translation matrix to shift the image center to the origin
r, c = img.shape
T = np.array([[1, 0, -c / 2.],
              [0, 1, -r / 2.],
              [0, 0, 1]])

# Skew, for perspective
S = np.array([[1, 0, 0],
              [0, 1.3, 0],
              [0, 1e-3, 1]])

img_rot = transform.homography(img, H)
img_rot_center_skew = transform.homography(img, S.dot(np.linalg.inv(T).dot(H).dot(T)))

f, (ax0, ax1, ax2) = plt.subplots(1, 3)
ax0.imshow(img, cmap=plt.cm.gray, interpolation='nearest')
ax1.imshow(img_rot, cmap=plt.cm.gray, interpolation='nearest')
ax2.imshow(img_rot_center_skew, cmap=plt.cm.gray, interpolation='nearest')
plt.show()