Esempio n. 1
0
def advanced_solve_ellipse(img, center, lengths, angle, phase_width, radius, num_points=500):
    """ This is a method in development. Better at optimizing angular correlations

    This method is in development. Due to the fact that an ellipse will have maximum 2-fold symmetry when the center
    is correctly determined and maximum 2*n-fold symmetry when the major/ minor axes as well as the angle of rotation
    is correct. This algorithm optimizes for these quantities.

    Parameters:
    -----------
    img: Array-like
        2-d Array of some image
    range: list
        The lower and upper limits to look at. Usually should just look at the first ring.
    num_points: int
        The number of points to look at to determine the characteristic ellipse.

    Return:
    -------------
    center: list
        The x and y coordinates of the center
    lengths: list
        The major and minor axes
    angle: float
        The angle of rotation for the ellipse
    """

    # Brute force testing method...

    x = np.linspace(-5,5,20)
    y = np.linspace(-5, 5, 20)

    pol =[[convert(img, angle=None, lengths=None, center=np.add(center[x1,y1]), phase_width=phase_width, radius=radius)
           for x1 in x]for y1 in y]
Esempio n. 2
0
 def test_simulation_correction(self):
     center = [263, 274]
     angle = np.pi/3
     lengths =[11,10]
     i = simulate_pattern(4,
                          k=100,
                          num_clusters=300,
                          probe_size=20,
                          center=center,
                          angle=angle,
                          lengths=lengths)
     i = np.random.poisson(i)
     c, l, a = solve_ellipse(i)
     # asserting the ellipse is correctly identified
     self.assertAlmostEqual(center[0], c[0], places=-1)
     self.assertAlmostEqual(center[1], c[1], places=-1)
     self.assertAlmostEqual(l[0]/l[1], max(lengths)/min(lengths), places=-1)
     self.assertAlmostEqual(angle, a, places=1)
     # converting to polar coordinates
     conversion = convert(img=i, center=c, lengths=l, angle=a)
     ac = angular_correlation(conversion, normalize=True)
     ps = power_spectrum(ac)
     #plt.imshow(i)
     #plt.show()
     plt.imshow(conversion[:, 0:359])
     plt.figure()
     plt.imshow(conversion[:, 360:719])
     plt.show()
     #plt.imshow(ac)
     plt.imshow(ps[:, 0:12])
     plt.show()
Esempio n. 3
0
 def test_polar_unwrapping(self):
     i = np.ones((512, 512)) * .01
     for j in range(0, 10):
         s = np.random.choice([2, 4, 6, 8, 10])
         print(s)
         v, ro = sample_spherical_cap()
         i = i + simulate_pattern(
             symmetry=s, k=12, radius=6, rotation_vector=v, rotation=ro)
     i = i + np.random.random((512, 512)) * np.max(i) / 4
     plt.imshow(i)
     plt.show()
     pol = convert(i,
                   center=(256, 256),
                   angle=None,
                   lengths=None,
                   radius=[0, 200],
                   phase_width=720)
     plt.imshow(pol)
     plt.show()
     ang = angular_correlation(pol)
     ps = power_spectrum(ang)
     plt.imshow(ang)
     plt.show()
     plt.imshow(ps[50:, 0:12], aspect=.05)
     plt.show()
Esempio n. 4
0
 def test_2d_convert(self):
     start = timeit()
     conversion = convert(self.d,
                          center=self.center,
                          angle=self.angle,
                          lengths=self.lengths,
                          phase_width=720)
     stop = timeit()
     print((stop - start))
     s = np.sum(conversion, axis=1)
     even = np.sum(conversion, axis=0)
     self.assertLess((s > max(s) / 2).sum(), 4)
Esempio n. 5
0
 def test_polar_unwrapping(self):
     i = simulate_pattern(symmetry=6,
                          k=12,
                          radius=6,
                          rotation_vector=(0, 0, 1),
                          rotation=0.6)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=0.2)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=0.7)
     i = i + simulate_pattern(symmetry=8,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=0.9)
     i = i + simulate_pattern(symmetry=10,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=0.8)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=1.5)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=6.4)
     i = i + simulate_pattern(symmetry=8,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=4.9)
     i = i + simulate_pattern(symmetry=10,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=2.3)
     i = i + simulate_pattern(symmetry=10,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=2.8)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=13.5)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=6.4)
     i = i + simulate_pattern(symmetry=8,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=5.9)
     i = i + simulate_pattern(symmetry=10,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=5.3)
     i = i + simulate_pattern(symmetry=10,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=3.8)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=12.5)
     i = i + simulate_pattern(symmetry=4,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=3.4)
     i = i + simulate_pattern(symmetry=8,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=4.9)
     i = i + simulate_pattern(symmetry=10,
                              k=12,
                              radius=6,
                              rotation_vector=(0, 0, 1),
                              rotation=3.8)
     i = i + np.random.random((512, 512)) * 3
     plt.imshow(i)
     plt.show()
     pol = convert(i,
                   center=(256, 256),
                   angle=None,
                   lengths=None,
                   radius=[0, 200],
                   phase_width=720)
     plt.imshow(pol)
     plt.show()
     ang = angular_correlation(pol)
     ps = power_spectrum(ang)
     plt.imshow(ang)
     plt.show()
     plt.imshow(ps[50:, 0:12], aspect=.05)
     plt.show()