Skip to content

Commit

Permalink
Merge pull request #45 from haesleinhuepf/code-generation
Browse files Browse the repository at this point in the history
Code generation works with napari-assistant
  • Loading branch information
haesleinhuepf committed Nov 4, 2023
2 parents aa88bbd + 28ae1e8 commit a094823
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
try:
from ._version import version as __version__
except ImportError:
__version__ = "0.14.0"

__version__ = "0.14.1"

__common_alias__ = "napoc"

from ._function import apply_object_selection, apply_object_classification, apply_object_segmentation, \
apply_pixel_classification, apply_probability_mapper
from ._object_merger import apply_object_merger

from ._function import napari_experimental_provide_function
from ._dock_widget import napari_experimental_provide_dock_widget
from ._dock_widget import napari_experimental_provide_dock_widget
60 changes: 52 additions & 8 deletions napari_accelerated_pixel_and_object_classification/_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from napari_tools_menu import register_function, register_dock_widget
from magicgui import magic_factory
from ._object_merger import Train_object_merger, Apply_object_merger
from ._utilities import wrap_api

from qtpy.QtWidgets import QTableWidget

Expand All @@ -29,6 +30,10 @@ def napari_experimental_provide_function():
Connected_component_labeling, Apply_object_classification,
Apply_object_merger]





def Train_pixel_classifier(
image: "napari.types.ImageData",
annotation : "napari.types.LabelsData",
Expand Down Expand Up @@ -68,16 +73,22 @@ def Train_probability_mapper(
result = clf.predict(features=feature_stack, image=image)
return result


def Apply_pixel_classification(image: "napari.types.ImageData",
model_filename : str = "PixelClassifier.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
warnings.warn("Apply_pixel_classification is deprecated use apply_pixel_classification instead.", DeprecationWarning)
return apply_pixel_classification(image, model_filename, viewer)

@register_function(menu="Segmentation / labeling > Semantic segmentation (apply pretrained, APOC)")
@time_slicer
def Apply_pixel_classification(image: "napari.types.ImageData",
@wrap_api
def apply_pixel_classification(image: "napari.types.ImageData",
model_filename : str = "PixelClassifier.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":

clf = PixelClassifier(opencl_filename=model_filename)
print("Hello world")
result = clf.predict(image=[image])
print("Result is ", result.shape, result.dtype)
return result

def Train_pixel_classifier_from_visible_image_layers(
Expand Down Expand Up @@ -132,19 +143,35 @@ def Train_object_segmentation(
return result


def Apply_probability_mapper(image: "napari.types.ImageData",
model_filename : str = "ProbabilityMapper.cl",
viewer: napari.Viewer = None) -> "napari.types.ImageData":
warnings.warn("Apply_probability_mapper is deprecated use apply_probability_mapper instead.", DeprecationWarning)
return apply_probability_mapper(image, model_filename, viewer)


@register_function(menu="Filtering > Probability Mapper (apply pretrained, APOC)")
@time_slicer
def Apply_probability_mapper(image: "napari.types.ImageData",
@wrap_api
def apply_probability_mapper(image: "napari.types.ImageData",
model_filename : str = "ProbabilityMapper.cl",
viewer: napari.Viewer = None) -> "napari.types.ImageData":
clf = ProbabilityMapper(opencl_filename=model_filename)
result = clf.predict(image=image)
return result


def Apply_object_segmentation(image: "napari.types.ImageData",
model_filename: str = "ObjectSegmenter.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
warnings.warn("Apply_object_segmentation is deprecated use apply_object_segmentation instead.",
DeprecationWarning)
return apply_object_segmentation(image, model_filename, viewer)

@register_function(menu="Segmentation / labeling > Object segmentation (apply pretrained, APOC)")
@time_slicer
def Apply_object_segmentation(image: "napari.types.ImageData",
@wrap_api
def apply_object_segmentation(image: "napari.types.ImageData",
model_filename : str = "ObjectSegmenter.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
clf = ObjectSegmenter(opencl_filename=model_filename)
Expand Down Expand Up @@ -288,7 +315,6 @@ def Train_object_classifier(image: "napari.types.ImageData",
update_model_analysis(table, clf)
viewer.window.add_dock_widget(table, name="Classifier statistics")


return result


Expand All @@ -310,9 +336,18 @@ def show_feature_correlation_matrix(layer: "napari.layers.Layer", method:str='pe
return correlation_matrix


def Apply_object_classification(image: "napari.types.ImageData",
labels: "napari.types.LabelsData",
model_filename : str = "ObjectClassifier.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
warnings.warn("Apply_object_classification is deprecated use apply_object_classification instead.", DeprecationWarning)
return apply_object_classification(image, labels, model_filename, viewer)


@register_function(menu="Segmentation post-processing > Object classification (apply pretrained, APOC)")
@time_slicer
def Apply_object_classification(image: "napari.types.ImageData",
@wrap_api
def apply_object_classification(image: "napari.types.ImageData",
labels: "napari.types.LabelsData",
model_filename : str = "ObjectClassifier.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
Expand All @@ -321,9 +356,18 @@ def Apply_object_classification(image: "napari.types.ImageData",
result = clf.predict(labels, image)
return result


def Apply_object_selection(image: "napari.types.ImageData",
labels: "napari.types.LabelsData",
model_filename : str = "ObjectSelector.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
warnings.warn("Apply_object_selection is deprecated use apply_object_selection instead.", DeprecationWarning)
apply_object_selection(image, labels, model_filename, viewer)

@register_function(menu="Segmentation post-processing > Object selection (apply pretrained, APOC)")
@time_slicer
def Apply_object_selection(image: "napari.types.ImageData",
@wrap_api
def apply_object_selection(image: "napari.types.ImageData",
labels: "napari.types.LabelsData",
model_filename : str = "ObjectSelector.cl",
viewer: napari.Viewer = None) -> "napari.types.LabelsData":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from napari_tools_menu import register_function, register_dock_widget
from apoc import ObjectMerger
from qtpy.QtWidgets import QTableWidget
import warnings
from ._utilities import wrap_api


@register_dock_widget(menu="Segmentation post-processing > Merge objects (APOC)")
Expand Down Expand Up @@ -89,9 +91,17 @@ def Train_object_merger(image: "napari.types.ImageData",
return result


def Apply_object_merger(image: "napari.types.ImageData",
labels: "napari.types.LabelsData",
model_filename : str = "LabelMerger.cl") -> "napari.types.LabelsData":
warnings.warn("Apply_object_merger is deprecated. Use apply_object_merger instead.", DeprecationWarning)
return apply_object_merger(image, labels, model_filename)


@register_function(menu="Segmentation post-processing > Merge objects (apply pretrained, APOC)")
@time_slicer
def Apply_object_merger(image: "napari.types.ImageData",
@wrap_api
def apply_object_merger(image: "napari.types.ImageData",
labels: "napari.types.LabelsData",
model_filename : str = "LabelMerger.cl") -> "napari.types.LabelsData":

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def wrap_api(func):
func.__module__ = "napari_accelerated_pixel_and_object_classification"
return func
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires =
superqt
imageio!=2.22.1
napari>=0.4.11 # https://github.com/napari/napari/issues/5511
napari-assistant>=0.4.7

[options.entry_points]
napari.plugin =
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from setuptools import setup

setup(
version='0.14.0'
version='0.14.1'
)

0 comments on commit a094823

Please sign in to comment.