Skip to content
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

Napari GUI: Fix voxel size precision, font size, and rearrange widgets #227

Merged
merged 4 commits into from
May 1, 2024
Merged
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
46 changes: 29 additions & 17 deletions plantseg/viewer/containers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import webbrowser

from PyQt5.QtCore import Qt
from magicgui.widgets import MainWindow
from magicgui.widgets import MainWindow, Label

from plantseg.viewer.widget.dataprocessing import widget_cropping, widget_add_layers
from plantseg.viewer.widget.dataprocessing import widget_label_processing
from plantseg.viewer.widget.dataprocessing import widget_rescaling, widget_gaussian_smoothing
from plantseg.viewer.widget.io import widget_open_file, export_stacks
from plantseg.viewer.widget.io import widget_open_file, widget_export_stacks
from plantseg.viewer.widget.predictions import widget_iterative_unet_predictions, widget_add_custom_model
from plantseg.viewer.widget.predictions import widget_unet_predictions, widget_test_all_unet_predictions
from plantseg.viewer.widget.predictions import widget_extra_pred_manager
Expand All @@ -19,6 +19,8 @@
from plantseg.viewer.widget.segmentation import widget_simple_dt_ws
from plantseg.viewer.widget.segmentation import widget_extra_seg_manager

STYLE_SLIDER = "font-size: 9pt;"


def setup_menu(container, path=None):
def _callback():
Expand All @@ -33,19 +35,16 @@ def _callback():
return container


def get_main():
def get_data_io():
container = MainWindow(widgets=[widget_open_file,
export_stacks,
widget_split_and_merge_from_scribbles,
widget_clean_scribble,
widget_filter_segmentation,
],
widget_export_stacks],
labels=False)
container = setup_menu(container, path='https://hci-unihd.github.io/plant-seg/chapters/plantseg_interactive_napari/index.html')
return container


def get_preprocessing_workflow():
widget_cropping.crop_z.native.setStyleSheet(STYLE_SLIDER)
container = MainWindow(widgets=[widget_gaussian_smoothing,
widget_rescaling,
widget_cropping,
Expand All @@ -65,22 +64,35 @@ def get_gasp_workflow():
return container


def get_extra_pred():
container = MainWindow(widgets=[widget_extra_pred_manager,
Label(),
widget_test_all_unet_predictions,
widget_iterative_unet_predictions,
widget_add_custom_model],
labels=False)
container = setup_menu(container, path='https://hci-unihd.github.io/plant-seg/chapters/plantseg_interactive_napari/extra_pred.html')
return container


def get_extra_seg():
container = MainWindow(widgets=[widget_extra_seg_manager,
Label(),
widget_dt_ws,
widget_lifted_multicut,
widget_fix_over_under_segmentation_from_nuclei,
widget_fix_false_positive_from_foreground_pmap],
widget_lifted_multicut],
labels=False)
container = setup_menu(container, path='https://hci-unihd.github.io/plant-seg/chapters/plantseg_interactive_napari/extra_seg.html')
return container


def get_extra_pred():
container = MainWindow(widgets=[widget_extra_pred_manager,
widget_test_all_unet_predictions,
widget_iterative_unet_predictions,
widget_add_custom_model],
def get_proofreading():
widget_fix_over_under_segmentation_from_nuclei.threshold.native.setStyleSheet(STYLE_SLIDER)
widget_fix_over_under_segmentation_from_nuclei.quantile.native.setStyleSheet(STYLE_SLIDER)
container = MainWindow(widgets=[widget_fix_over_under_segmentation_from_nuclei,
widget_fix_false_positive_from_foreground_pmap,
widget_split_and_merge_from_scribbles,
widget_clean_scribble,
widget_filter_segmentation],
labels=False)
container = setup_menu(container, path='https://hci-unihd.github.io/plant-seg/chapters/plantseg_interactive_napari/extra_pred.html')
container = setup_menu(container, path='https://hci-unihd.github.io/plant-seg/chapters/plantseg_interactive_napari/extra_seg.html')
return container
20 changes: 10 additions & 10 deletions plantseg/viewer/viewer.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import napari

from plantseg.viewer.containers import get_extra_seg, get_extra_pred
from plantseg.viewer.containers import get_gasp_workflow, get_preprocessing_workflow, get_main
from plantseg.viewer.containers import get_extra_pred, get_extra_seg, get_proofreading
from plantseg.viewer.containers import get_gasp_workflow, get_preprocessing_workflow, get_data_io
from plantseg.viewer.logging import napari_formatted_logging
from plantseg.viewer.widget.proofreading.proofreading import setup_proofreading_keybindings


def run_viewer():
viewer = napari.Viewer()
main_container = get_main()
main_w = viewer.window.add_dock_widget(main_container, name='Main')
main_container = get_data_io()
main_w = viewer.window.add_dock_widget(main_container, name='Data')

setup_proofreading_keybindings(viewer)

for _containers, name in [(get_preprocessing_workflow(), 'Data - Processing'),
(get_gasp_workflow(), 'UNet + Segmentation'),
(get_extra_pred(), 'Extra-Pred'),
(get_extra_seg(), 'Extra-Seg'),
]:
for _containers, name in [(get_preprocessing_workflow(), 'Preprocessing'),
(get_gasp_workflow(), 'Main'),
(get_extra_pred(), 'Prediction'),
(get_extra_seg(), 'Segmentation'),
(get_proofreading(), 'Proofreading')]:
_container_w = viewer.window.add_dock_widget(_containers, name=name)
viewer.window._qt_window.tabifyDockWidget(main_w, _container_w)

napari_formatted_logging('Plantseg is ready!', thread='Main', level='info')
napari_formatted_logging('Plantseg is ready!', thread='run_viewer', level='info')
napari.run()
6 changes: 4 additions & 2 deletions plantseg/viewer/widget/dataprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ class RescaleType(Enum):
image={'label': 'Image or Label',
'tooltip': 'Layer to apply the rescaling.'},
rescaling_factor={'label': 'Rescaling factor',
'tooltip': 'Define the scaling factor to use for resizing the input image.'},
'tooltip': 'Define the scaling factor to use for resizing the input image.',
'options': {'step': 0.00001}},
out_voxel_size={'label': 'Out voxel size',
'tooltip': 'Define the output voxel size. Units are same as imported, '
'(if units are missing default is "um").'},
'(if units are missing default is "um").',
'options': {'step': 0.00001}},
reference_layer={'label': 'Reference layer',
'tooltip': 'Rescale to same voxel size as selected layer.'},
reference_model={'label': 'Reference model',
Expand Down
46 changes: 23 additions & 23 deletions plantseg/viewer/widget/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ def checkout(*args):
workflow_name={'label': 'Workflow name',
'tooltip': 'Name of the workflow object.'},
)
def export_stacks(images: List[Tuple[Layer, str]],
directory: Path = Path.home(),
export_format: str = 'tiff',
rescale_to_original_resolution: bool = True,
data_type: str = 'float32',
workflow_name: str = 'workflow',
) -> None:
def widget_export_stacks(images: List[Tuple[Layer, str]],
directory: Path = Path.home(),
export_format: str = 'tiff',
rescale_to_original_resolution: bool = True,
data_type: str = 'float32',
workflow_name: str = 'workflow',
) -> None:
export_name = []

for i, (image, image_custom_name) in enumerate(images):
Expand Down Expand Up @@ -457,25 +457,25 @@ def export_stacks(images: List[Tuple[Layer, str]],
napari_formatted_logging(f'Workflow correctly exported', thread='Export stack')


export_stacks.directory.hide()
export_stacks.export_format.hide()
export_stacks.rescale_to_original_resolution.hide()
export_stacks.data_type.hide()
export_stacks.workflow_name.hide()
widget_export_stacks.directory.hide()
widget_export_stacks.export_format.hide()
widget_export_stacks.rescale_to_original_resolution.hide()
widget_export_stacks.data_type.hide()
widget_export_stacks.workflow_name.hide()


@export_stacks.images.changed.connect
@widget_export_stacks.images.changed.connect
def _on_images_changed(images_list: List[Tuple[Layer, str]]):
images_list = return_value_if_widget(images_list)
if len(images_list) > 0:
export_stacks.directory.show()
export_stacks.export_format.show()
export_stacks.rescale_to_original_resolution.show()
export_stacks.data_type.show()
export_stacks.workflow_name.show()
widget_export_stacks.directory.show()
widget_export_stacks.export_format.show()
widget_export_stacks.rescale_to_original_resolution.show()
widget_export_stacks.data_type.show()
widget_export_stacks.workflow_name.show()
else:
export_stacks.directory.hide()
export_stacks.export_format.hide()
export_stacks.rescale_to_original_resolution.hide()
export_stacks.data_type.hide()
export_stacks.workflow_name.hide()
widget_export_stacks.directory.hide()
widget_export_stacks.export_format.hide()
widget_export_stacks.rescale_to_original_resolution.hide()
widget_export_stacks.data_type.hide()
widget_export_stacks.workflow_name.hide()
15 changes: 11 additions & 4 deletions plantseg/viewer/widget/predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _on_widget_iterative_unet_predictions_image_change(image: Image):
new_model_name={'label': 'New model name'},
model_location={'label': 'Model location',
'mode': 'd'},
resolution={'label': 'Resolution'},
resolution={'label': 'Resolution', 'options': {'step': 0.00001}},
description={'label': 'Description'},
dimensionality={'label': 'Dimensionality',
'tooltip': 'Dimensionality of the model (2D or 3D). '
Expand Down Expand Up @@ -339,12 +339,10 @@ def widget_add_custom_model(new_model_name: str = 'custom_model',
"Iterative UNet": widget_iterative_unet_predictions,
"Add Custom Model": widget_add_custom_model}

for _widget in registered_extra_pred_widgets.values():
_widget.hide()


@magicgui(auto_call=True,
widget_name={'label': 'Widget Selection',
'tooltip': 'Show only one widget if the Napari interface is too long.',
'choices': list(registered_extra_pred_widgets.keys())})
def widget_extra_pred_manager(widget_name: str) -> None:
napari_formatted_logging(f'Showing widget: {widget_name}', thread='Extra-Pred', level='info')
Expand All @@ -353,3 +351,12 @@ def widget_extra_pred_manager(widget_name: str) -> None:
value.show()
else:
value.hide()

TOO_MANY_WIDGES = False # Set to True if there are too many widgets to show

if TOO_MANY_WIDGES:
for _widget in registered_extra_pred_widgets.values():
_widget.hide()

# widget_extra_pred_manager.enabled=TOO_MANY_WIDGES

17 changes: 10 additions & 7 deletions plantseg/viewer/widget/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,12 @@ def widget_fix_false_positive_from_foreground_pmap(segmentation: Labels,


register_extra_seg_widgets = {"Watershed": widget_dt_ws,
"Lifted MultiCut": widget_lifted_multicut,
"Fix Over/Under Segmentation from Nuclei": widget_fix_over_under_segmentation_from_nuclei,
"Fix False Positives from Foreground Pmap": widget_fix_false_positive_from_foreground_pmap,
}

for _widget in register_extra_seg_widgets.values():
_widget.hide()
"Lifted MultiCut": widget_lifted_multicut}


@magicgui(auto_call=True,
widget_name={'label': 'Widget Selection',
'tooltip': 'Show only one widget if the Napari interface is too long.',
'choices': list(register_extra_seg_widgets.keys())})
def widget_extra_seg_manager(widget_name: str) -> None:
napari_formatted_logging(f'Showing {widget_name} widget',
Expand All @@ -388,3 +383,11 @@ def widget_extra_seg_manager(widget_name: str) -> None:
value.show()
else:
value.hide()

TOO_MANY_WIDGES = False # Set to True if there are too many widgets to show

if TOO_MANY_WIDGES:
for _widget in register_extra_seg_widgets.values():
_widget.hide()

# widget_extra_seg_manager.enabled=TOO_MANY_WIDGES
Loading