Beispiel #1
0
def test_inert_ratio_prnc_simple_2():
    c = np.array([[0, 0],
                  [1, 1],
                  [2, 2],
                  [3, 3],
                  [4, 2],
                  [5, 1],
                  [4, 0],
                  [3, -1],
                  [2, -2],
                  [1, -1],
                  [0, 0]])
    raw = ir.get_inert_ratio_raw(c)
    prnc = ir.get_inert_ratio_prnc(c)
    tilt = ir.get_tilt(c)
    assert np.allclose(raw, 1)
    assert np.allclose(prnc, 1.5)
    assert np.allclose(tilt, np.pi/4)
Beispiel #2
0
def test_inert_ratio_prnc_simple_1():
    c = np.array([[0, 0],
                  [0, 1],
                  [0, 2],
                  [1, 2],
                  [2, 2],
                  [3, 2],
                  [3, 1],
                  [3, 0],
                  [2, 0],
                  [1, 0],
                  [0, 0]])
    raw = ir.get_inert_ratio_raw(c)
    prnc = ir.get_inert_ratio_prnc(c)
    tilt = ir.get_tilt(c)
    assert np.allclose(raw, 1.5)
    assert np.allclose(prnc, 1.5)
    assert np.allclose(tilt, 0)
Beispiel #3
0
def test_inert_ratio_prnc():
    """Test equivalence of inert_ratio_raw and inert_ratio_prnc"""
    t = np.linspace(0, 2*np.pi, 300)

    x1 = 1.7 * np.cos(t)
    y1 = 1.1 * np.sin(t)
    c1 = np.dstack((x1, y1))[0]

    phi = np.arctan2(y1, x1)
    rho = np.sqrt(x1**2 + y1**2)

    for theta in np.linspace(0.1, 2*np.pi, 14):  # arbitrary rotation
        for pos_x in np.linspace(-5, 20, 8):  # arbitrary x shift
            for pos_y in np.linspace(-4.6, 17, 4):  # arbitrary y shift
                x2 = rho * np.cos(phi + theta) + pos_x
                y2 = rho * np.sin(phi + theta) + pos_y

                c2 = np.dstack((x2, y2))[0]
                raw = ir.get_inert_ratio_raw(c1)
                prnc = ir.get_inert_ratio_prnc(c2)

                assert np.allclose(raw, prnc, rtol=0, atol=1e-10)
Beispiel #4
0
))
rr, cc = polygon(pol1[:, 0], pol1[:, 1], img1.shape)
img1[rr, cc] = True

img2 = rotate(np.array(img1, dtype=int), 5, reshape=False)
img2 = img2 > .5

cont1 = contour.get_contour(img1)
cont2 = contour.get_contour(img2)

# convert mask to inertia ratio
# regular inertia ratio
rir1 = inert_ratio.get_inert_ratio_raw(cont1)
rir2 = inert_ratio.get_inert_ratio_raw(cont2)
# principal inertia ratio
pir1 = inert_ratio.get_inert_ratio_prnc(cont1)
pir2 = inert_ratio.get_inert_ratio_prnc(cont2)

fig = plt.figure(figsize=(7, 3))

ax1 = plt.subplot(221, title="rectangle")
ax1.imshow(img1, cmap="gray_r")
ax1.text(.5,
         .5,
         "inertia ratio: {:.1f}\nprincipal inertia ratio: {:.1f}".format(
             rir1, pir1),
         transform=ax1.transAxes,
         color="w",
         va="center",
         ha="center")