Skip to content
Snippets Groups Projects
Commit 9bce8268 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Generalized to flattening multichannel images

parent 1092b9c5
No related branches found
No related tags found
No related merge requests found
...@@ -106,7 +106,7 @@ class TestZStackDerivedDataProducts(unittest.TestCase): ...@@ -106,7 +106,7 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
dff['centroid-0'].to_numpy(), dff['centroid-0'].to_numpy(),
dff['centroid-1'].to_numpy(), dff['centroid-1'].to_numpy(),
dff['zi'].to_numpy(), dff['zi'].to_numpy(),
self.stack.get_one_channel_data(1), self.stack
) )
self.assertEqual(img.shape[0:2], self.stack.shape[0:2]) self.assertEqual(img.shape[0:2], self.stack.shape[0:2])
......
...@@ -154,20 +154,18 @@ def project_stack_from_focal_points( ...@@ -154,20 +154,18 @@ def project_stack_from_focal_points(
zz: np.ndarray, zz: np.ndarray,
stack: GenericImageDataAccessor, stack: GenericImageDataAccessor,
degree: int = 2, degree: int = 2,
): ) -> np.ndarray:
# TODO: add weights
""" """
Given a set of 3D points, project a multichannel z-stack Given a set of 3D points, project a multichannel z-stack based on a surface fit of the provided points
:param xx: :param xx: vector of point x-coordinates
:param yy: :param yy: vector of point y-coordinates
:param zz: :param zz: vector of point z-coordinates
:param stack: :param stack: z-stack to project
:param degree: :param degree: order of polynomial to fit
:return: :return: multichannel 2d projected image array
""" """
assert xx.shape == yy.shape assert xx.shape == yy.shape
assert xx.shape == zz.shape assert xx.shape == zz.shape
assert stack.chroma == 1
poly = PolynomialFeatures(degree=degree) poly = PolynomialFeatures(degree=degree)
X = np.stack([xx, yy]).T X = np.stack([xx, yy]).T
...@@ -175,20 +173,23 @@ def project_stack_from_focal_points( ...@@ -175,20 +173,23 @@ def project_stack_from_focal_points(
model = LinearRegression(fit_intercept=False) model = LinearRegression(fit_intercept=False)
model.fit(features, zz) model.fit(features, zz)
output_shape = stack.hw xy_indices = np.indices(stack.hw).reshape(2, -1).T
xy_indices = np.indices(output_shape).reshape(2, -1).T
xy_features = np.dot( xy_features = np.dot(
poly.fit_transform(xy_indices, zz), poly.fit_transform(xy_indices, zz),
model.coef_ model.coef_
) )
zi_image = xy_features.reshape( zi_image = xy_features.reshape(
output_shape stack.hw
).round().clip( ).round().clip(
0, stack.nz 0, stack.nz
).astype('uint16') ).astype('uint16')
return np.take_along_axis( return np.take_along_axis(
stack.data[:, :, 0, :], stack.data,
np.expand_dims(zi_image, 2), np.repeat(
axis=2 np.expand_dims(zi_image, (2, 3)),
).reshape(output_shape) stack.chroma,
axis=2
),
axis=3
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment