Skip to content

Commit

Permalink
Update use of napari api (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Jul 11, 2024
1 parent 4dbc1e6 commit 52ff499
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 19 deletions.
1 change: 0 additions & 1 deletion brainglobe_segmentation/layout/gui_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

POINT_SIZE = 100
SPLINE_SIZE = 50
NUM_COLORS = 10
BRUSH_SIZE = 250
SPLINE_POINTS_DEFAULT = 1000
SPLINE_SMOOTHING_DEFAULT = 0.1
Expand Down
15 changes: 3 additions & 12 deletions brainglobe_segmentation/regions/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def add_new_label_layer(
base_image,
name="region",
selected_label=1,
num_colors=10,
brush_size=30,
):
"""
Expand All @@ -22,28 +21,24 @@ def add_new_label_layer(
referencing)
:param str name: Name of the new labels layer
:param int selected_label: Label ID to be preselected
:param int num_colors: How many colors (labels)
:param int brush_size: Default size of the label brush
:return label_layer: napari labels layer
"""
labels = np.empty_like(base_image)
label_layer = viewer.add_labels(labels, num_colors=num_colors, name=name)
label_layer = viewer.add_labels(labels, name=name)
label_layer.n_dimensional = True
label_layer.selected_label = selected_label
label_layer.brush_size = brush_size
return label_layer


def add_new_region_layer(
viewer, label_layers, image_like, brush_size, num_colors
):
def add_new_region_layer(viewer, label_layers, image_like, brush_size):
num = len(label_layers)
new_label_layer = add_new_label_layer(
viewer,
image_like,
name=f"region_{num}",
brush_size=brush_size,
num_colors=num_colors,
)
new_label_layer.mode = "PAINT"
label_layers.append(new_label_layer)
Expand All @@ -53,23 +48,19 @@ def add_existing_label_layers(
viewer,
label_file,
selected_label=1,
num_colors=10,
brush_size=30,
):
"""
Loads an existing image as a napari labels layer
:param viewer: Napari viewer instance
:param label_file: Filename of the image to be loaded
:param int selected_label: Label ID to be preselected
:param int num_colors: How many colors (labels)
:param int brush_size: Default size of the label brush
:return label_layer: napari labels layer
"""
label_file = Path(label_file)
labels = tifffile.imread(label_file)
label_layer = viewer.add_labels(
labels, num_colors=num_colors, name=label_file.stem
)
label_layer = viewer.add_labels(labels, name=label_file.stem)
label_layer.selected_label = selected_label
label_layer.brush_size = brush_size
return label_layer
Expand Down
4 changes: 0 additions & 4 deletions brainglobe_segmentation/segmentation_panels/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
CALCULATE_VOLUMES_DEFAULT,
COLUMN_WIDTH,
IMAGE_FILE_EXT,
NUM_COLORS,
SAVE_DEFAULT,
SEGM_METHODS_PANEL_ALIGN,
SUMMARIZE_VOLUMES_DEFAULT,
Expand All @@ -34,7 +33,6 @@ def __init__(
save_default=SAVE_DEFAULT,
brush_size=BRUSH_SIZE,
image_file_extension=IMAGE_FILE_EXT,
num_colors=NUM_COLORS,
):
super(RegionSeg, self).__init__()
self.parent = parent
Expand All @@ -46,7 +44,6 @@ def __init__(
# Brushes / ...
self.brush_size_default = BRUSH_SIZE # Keep track of default
self.brush_size = brush_size # Initialise
self.num_colors = num_colors

# File formats
self.image_file_extension = image_file_extension
Expand Down Expand Up @@ -168,7 +165,6 @@ def add_new_region(self):
self.parent.label_layers,
self.parent.base_layer.data,
self.brush_size,
self.num_colors,
)

def add_region_from_existing_layer(self, override=False):
Expand Down
2 changes: 1 addition & 1 deletion brainglobe_segmentation/tracks/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def track_analysis(
viewer.add_points(
spline,
size=napari_spline_size,
edge_color="cyan",
border_color="cyan",
face_color="cyan",
blending="additive",
opacity=0.7,
Expand Down
1 change: 0 additions & 1 deletion tests/tests/test_integration/test_gui/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def check_defaults(widget):
assert widget.track_seg.spline_size == int(50 / widget.mean_voxel_size)
assert widget.track_seg.track_file_extension == ".points"
assert widget.region_seg.image_file_extension == ".tiff"
assert widget.region_seg.num_colors == 10
assert widget.region_seg.brush_size == int(250 / widget.mean_voxel_size)
assert widget.track_seg.spline_points_default == 1000
assert widget.track_seg.spline_smoothing_default == 0.1
Expand Down

0 comments on commit 52ff499

Please sign in to comment.