Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 3D_UNet
  • 3d_watershed
  • conv_zarr_tiff_folders
  • convert_tiff_folders
  • layered_surface_segmentation
  • main
  • memmap_txrm
  • notebook_update
  • notebooks
  • notebooksv1
  • optimize_scaleZYXdask
  • save_files_function
  • scaleZYX_mean
  • test
  • threshold-exploration
  • tr_val_te_splits
  • v0.2.0
  • v0.3.0
  • v0.3.1
  • v0.3.2
  • v0.3.3
  • v0.3.9
  • v0.4.0
  • v0.4.1
24 results

Target

Select target project
  • QIM/tools/qim3d
1 result
Select Git revision
  • 3D_UNet
  • 3d_watershed
  • conv_zarr_tiff_folders
  • convert_tiff_folders
  • layered_surface_segmentation
  • main
  • memmap_txrm
  • notebook_update
  • notebooks
  • notebooksv1
  • optimize_scaleZYXdask
  • save_files_function
  • scaleZYX_mean
  • test
  • threshold-exploration
  • tr_val_te_splits
  • v0.2.0
  • v0.3.0
  • v0.3.1
  • v0.3.2
  • v0.3.3
  • v0.3.9
  • v0.4.0
  • v0.4.1
24 results
Show changes
Showing
with 418 additions and 253 deletions
from ._layers import get_lines, segment_layers
from ._local_thickness import local_thickness from ._local_thickness import local_thickness
from ._structure_tensor import structure_tensor from ._structure_tensor import structure_tensor
from ._layers import segment_layers, get_lines
import numpy as np import numpy as np
from slgbuilder import GraphObject from slgbuilder import GraphObject, MaxflowBuilder
from slgbuilder import MaxflowBuilder
def segment_layers(data: np.ndarray,
def segment_layers(
data: np.ndarray,
inverted: bool = False, inverted: bool = False,
n_layers: int = 1, n_layers: int = 1,
delta: float = 1, delta: float = 1,
min_margin: int = 10, min_margin: int = 10,
max_margin: int = None, max_margin: int = None,
wrap: bool = False wrap: bool = False,
) -> list: ) -> list:
""" """
Works on 2D and 3D data. Works on 2D and 3D data.
...@@ -56,11 +57,15 @@ def segment_layers(data: np.ndarray, ...@@ -56,11 +57,15 @@ def segment_layers(data: np.ndarray,
if inverted: if inverted:
data = ~data data = ~data
else: else:
raise TypeError(F"Data has to be type np.ndarray. Your data is of type {type(data)}") raise TypeError(
f'Data has to be type np.ndarray. Your data is of type {type(data)}'
)
helper = MaxflowBuilder() helper = MaxflowBuilder()
if not isinstance(n_layers, int): if not isinstance(n_layers, int):
raise TypeError(F"Number of layers has to be positive integer. You passed {type(n_layers)}") raise TypeError(
f'Number of layers has to be positive integer. You passed {type(n_layers)}'
)
if n_layers == 1: if n_layers == 1:
layer = GraphObject(data) layer = GraphObject(data)
...@@ -69,17 +74,21 @@ def segment_layers(data: np.ndarray, ...@@ -69,17 +74,21 @@ def segment_layers(data: np.ndarray,
layers = [GraphObject(data) for _ in range(n_layers)] layers = [GraphObject(data) for _ in range(n_layers)]
helper.add_objects(layers) helper.add_objects(layers)
for i in range(len(layers) - 1): for i in range(len(layers) - 1):
helper.add_layered_containment(layers[i], layers[i+1], min_margin=min_margin, max_margin=max_margin) helper.add_layered_containment(
layers[i], layers[i + 1], min_margin=min_margin, max_margin=max_margin
)
else: else:
raise ValueError(F"Number of layers has to be positive integer. You passed {n_layers}") raise ValueError(
f'Number of layers has to be positive integer. You passed {n_layers}'
)
helper.add_layered_boundary_cost() helper.add_layered_boundary_cost()
if delta > 1: if delta > 1:
delta = int(delta) delta = int(delta)
elif delta <= 0: elif delta <= 0:
raise ValueError(F'Delta has to be positive number. You passed {delta}') raise ValueError(f'Delta has to be positive number. You passed {delta}')
helper.add_layered_smoothness(delta=delta, wrap=bool(wrap)) helper.add_layered_smoothness(delta=delta, wrap=bool(wrap))
helper.solve() helper.solve()
if n_layers == 1: if n_layers == 1:
...@@ -89,6 +98,7 @@ def segment_layers(data: np.ndarray, ...@@ -89,6 +98,7 @@ def segment_layers(data: np.ndarray,
return segmentations return segmentations
def get_lines(segmentations: list[np.ndarray]) -> list: def get_lines(segmentations: list[np.ndarray]) -> list:
""" """
Expects list of arrays where each array is 2D segmentation with only 2 classes. This function gets the border between those two Expects list of arrays where each array is 2D segmentation with only 2 classes. This function gets the border between those two
...@@ -99,6 +109,7 @@ def get_lines(segmentations:list[np.ndarray]) -> list: ...@@ -99,6 +109,7 @@ def get_lines(segmentations:list[np.ndarray]) -> list:
Returns: Returns:
segmentation_lines (list): List of 1D numpy arrays segmentation_lines (list): List of 1D numpy arrays
""" """
segmentation_lines = [np.argmin(s, axis=0) - 0.5 for s in segmentations] segmentation_lines = [np.argmin(s, axis=0) - 0.5 for s in segmentations]
return segmentation_lines return segmentation_lines
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.