4 from skimage
import feature
7 center_mask = make_circular_aperture(mask_diameter)(image.grid)
8 mask = center_mask * ((image / np.nanstd(image)) < threshold)
11 xc = np.sum(mask * image.grid.x) / np.sum(mask)
12 yc = np.sum(mask * image.grid.y) / np.sum(mask)
13 return np.array([xc, yc])
15 return np.array([0.0, 0.0])
18 '''Measure the distance from the knife edge focal plane mask to the center of an image.
23 image : array of floats
26 The knife edge mask angle with respect to the image's x-axis. Default: 0.
27 mask_diameter: The diameter of the circular mask applied to the image for edge detection. Default: 200.
28 threshold: The sigma used to mask pixels along the circular mask edge. Default: 0.5.
33 A NumPy array containing the knife edge distance in X and Y with respect to the image center.
35 THETA = np.deg2rad(theta)
39 center_mask = make_circular_aperture(mask_diameter)(grid)
40 mask = ((image / np.std(image)) < threshold)
43 masked_im = (center_mask*mask)
46 edge = feature.canny(masked_im.shaped, sigma=4)
48 edge_field = Field(edge.ravel(), image.grid)
51 x_edge = image.grid.x[edge_field>0]
52 y_edge = image.grid.y[edge_field>0]
55 d_normal = x_edge * np.sin(THETA) + y_edge * np.cos(THETA)
56 d_parallel = x_edge * np.sin(THETA + np.pi/2) + y_edge * np.cos(THETA + np.pi/2)
57 d = np.hypot(d_normal, d_parallel)
60 min_dist_indx = np.argmin(abs(d))
62 return np.array([0.0, y_edge[min_dist_indx]])
def measure_center_position(image, threshold=1, mask_diameter=20)
def knife_edge_dist(image, theta=-0.47, mask_diameter=200, threshold=0.5)