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()
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()
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()
def test_power_spectrum(self): ac1 = angular_correlation(self.test1, normalize=False) ac2 = angular_correlation(self.test1, self.mask)
def test_angular_correlation_mask(self): test = np.ma.masked_array(np.random.rand(10, 10)) test.mask= np.zeros((10, 10), dtype=bool) test.mask[0:5, 2:4] = True ac1 = angular_correlation(test)
def test_angular_correlation(self): ac1 = angular_correlation(self.test1) self.assertAlmostEqual(np.mean(ac1[:, 0]), .33, places=1) self.assertAlmostEqual(np.mean(ac1[:, 360]), 0, places=2)