Skip to content

Issue/size param automation #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion camera_alignment_core/alignment_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def generate_alignment_matrix(
log.debug("crop rings")
ref_crop, crop_dims = CropRings(
img=optical_control_image[reference_channel, ref_center_z, :, :],
pixel_size=px_size_xy,
pixel_size_um=px_size_xy,
magnification=magnification,
filter_px_size=50,
).run()
Expand Down
4 changes: 2 additions & 2 deletions camera_alignment_core/alignment_utils/crop_rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class CropRings:
def __init__(
self,
img: NDArray[np.uint16],
pixel_size: float,
pixel_size_um: float,
magnification: int,
filter_px_size: int = 50,
bead_distance: int = BEAD_DISTANCE_UM,
):
self.img = img
self.bead_dist_px = bead_distance / pixel_size
self.bead_dist_px = bead_distance / pixel_size_um
self.filter_px_size = filter_px_size
self.magnification = magnification

Expand Down
21 changes: 15 additions & 6 deletions camera_alignment_core/alignment_utils/segment_rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@
log = logging.getLogger(LOGGER_NAME)

BEAD_DISTANCE_UM = 15
CROSS_SIZE_UM = 7.5 * 6 * 10 ** -6
RING_RADIUS_UM = 0.7 * 10 ** -6
CROSS_SIZE_UM = 7.5 * 6
RING_RADIUS_UM = 0.7


class SegmentRings:
def __init__(
self,
img: np.typing.NDArray[np.uint16],
pixel_size: float,
pixel_size_um: float,
magnification: int,
thresh: Optional[Tuple[float, float]] = None,
bead_distance_um: float = BEAD_DISTANCE_UM,
cross_size_um: float = CROSS_SIZE_UM,
ring_radius_um: float = RING_RADIUS_UM,
):
self.img = img
self.pixel_size = pixel_size
self.pixel_size = pixel_size_um
self.magnification = magnification

self.cross_size_px = cross_size_um / self.pixel_size
self.ring_size_px = math.pi * (ring_radius_um / self.pixel_size) ** 2
self.bead_dist_px = bead_distance_um / self.pixel_size
self.ring_radius_px = ring_radius_um / pixel_size_um

if thresh is not None:
self.thresh = thresh
Expand Down Expand Up @@ -173,8 +174,8 @@ def segment_rings_dot_filter(
seg_cross: np.typing.NDArray[np.bool_],
num_beads: int,
minArea: int,
size_param: Optional[float] = None,
search_range: Tuple[float, float] = (0, 0.75),
size_param: float = 2.5,
) -> Tuple[
np.typing.NDArray[np.uint16], np.typing.NDArray[np.uint16], Optional[float]
]:
Expand All @@ -187,8 +188,9 @@ def segment_rings_dot_filter(
seg_cross: binary mask of the center cross object
num_beads: expected number of beads
minArea: minimum area of rings, any segmented object below this size will be filtered out
size_param: size parameter of dot filter (default is ring radius in pixels)
search_range: initial search range of filter parameter
size_param: size parameter of dot filter


Returns
-------
Expand All @@ -200,6 +202,13 @@ def segment_rings_dot_filter(
img = np.zeros((1, img_2d.shape[0], img_2d.shape[1]))
img[0, :, :] = img_2d

if size_param is None:
size_param = self.ring_radius_px - 0.5

# use previous default value (2.5) if parameter is lower
if size_param < 2.5:
size_param = 2.5

thresh = None
for seg_param in np.linspace(search_range[1], search_range[0], 500):
s2_param = [[size_param, seg_param]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_run(self):
# Act
seg_rings, _, _, _ = SegmentRings(
img=numpy.max(synthetic_image, axis=0),
pixel_size=1,
pixel_size_um=1,
magnification=1,
thresh=(50, 99),
bead_distance_um=10,
Expand Down