Skip to content
Snippets Groups Projects
Commit 7fec5e8a authored by Andrey Aristov's avatar Andrey Aristov
Browse files

strip dimensions

parent 82313187
No related branches found
No related tags found
No related merge requests found
...@@ -151,10 +151,8 @@ def get_gradient(bf_data: np.ndarray, smooth=10): ...@@ -151,10 +151,8 @@ def get_gradient(bf_data: np.ndarray, smooth=10):
applies gaussian filter applies gaussian filter
Returns SegmentedImage object Returns SegmentedImage object
""" """
assert ( data = strip_dimensions(bf_data)
bf_data[0].ndim == 2 gradient = get_2d_gradient(data)
), f"expected 2D shape, got shape {bf_data[0].shape}"
gradient = get_2d_gradient(bf_data[0])
smoothed_gradient = gaussian_filter(gradient, smooth) smoothed_gradient = gaussian_filter(gradient, smooth)
# sm = multiwell.gaussian_filter(well, smooth) # sm = multiwell.gaussian_filter(well, smooth)
return smoothed_gradient.reshape(bf_data.shape) return smoothed_gradient.reshape(bf_data.shape)
...@@ -166,7 +164,8 @@ def threshold_gradient( ...@@ -166,7 +164,8 @@ def threshold_gradient(
fill: bool = True, fill: bool = True,
erode: int = 1, erode: int = 1,
): ):
regions = smoothed_gradient[0] > thr * smoothed_gradient[0].max() data = strip_dimensions(smoothed_gradient)
regions = data > thr * data.max()
if fill: if fill:
regions = binary_fill_holes(regions) regions = binary_fill_holes(regions)
...@@ -178,6 +177,13 @@ def threshold_gradient( ...@@ -178,6 +177,13 @@ def threshold_gradient(
return labels.reshape(smoothed_gradient.shape) return labels.reshape(smoothed_gradient.shape)
def strip_dimensions(array:np.ndarray):
data = array.copy()
while data.ndim > 2:
assert data.shape[0] == 1, f'Unexpected multidimensional data! {data.shape}'
data = data[0]
return data
def get_2d_gradient(xy): def get_2d_gradient(xy):
gx, gy = np.gradient(xy) gx, gy = np.gradient(xy)
return np.sqrt(gx**2 + gy**2) return np.sqrt(gx**2 + gy**2)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment