diff --git a/server/__pycache__/helper.cpython-36.pyc b/server/__pycache__/helper.cpython-36.pyc new file mode 100644 index 0000000..2ea804e Binary files /dev/null and b/server/__pycache__/helper.cpython-36.pyc differ diff --git a/server/__pycache__/protocol.cpython-36.pyc b/server/__pycache__/protocol.cpython-36.pyc new file mode 100644 index 0000000..bd07ad7 Binary files /dev/null and b/server/__pycache__/protocol.cpython-36.pyc differ diff --git a/server/helper.py b/server/helper.py index 6601606..16a45e6 100644 --- a/server/helper.py +++ b/server/helper.py @@ -13,6 +13,11 @@ def print_matrix(itkmat, size=(3, 3)): sys.stdout.write('{} '.format(itkmat(i, j))) sys.stdout.write('\n') +def itk_image_dimension(itkimage): + return int("".join([char for char in repr(itkimage).split('itkImagePython.')[1].split(';')[0][8:] if char.isnumeric()])) +def itk_pixel_type(itkimage): + return getattr(itk, "".join([char for char in repr(itkimage).split('itkImagePython.')[1].split(';')[0][8:] if char.isupper()])) + # modified from: https://github.com/InsightSoftwareConsortium/itk-jupyter-widgets/blob/master/itkwidgets/trait_types.py#L49 def _itk_image_to_type(itkimage): component_str = repr(itkimage).split('itkImagePython.')[1].split(';')[0][8:] diff --git a/server/protocol.py b/server/protocol.py index 895a137..a099a30 100644 --- a/server/protocol.py +++ b/server/protocol.py @@ -7,6 +7,7 @@ class Protocol(helper.ObjectProtocol): @rpc('median_filter') @helper.objdir_wrap def median_filter(self, image, radius): + print (itk.__path__) itk_image = helper.vtkjs_to_itk_image(image) median_filter = itk.MedianImageFilter[type(itk_image), type(itk_image)].New() @@ -19,6 +20,23 @@ def median_filter(self, image, radius): # TODO auto-serialize in objdir_wrap? return helper.itk_to_vtkjs_image(result) + @rpc('otsu_segment_filter') + @helper.objdir_wrap + def otsu_segment_filter(self, image): + print (itk.__path__) + itk_image = helper.vtkjs_to_itk_image(image) + + otsu_filter = itk.TubeTK.SegmentUsingOtsuThreshold[helper.itk_pixel_type(itk_image), + helper.itk_image_dimension(itk_image), + helper.itk_pixel_type(itk_image)].New() + otsu_filter.SetInput(itk_image) + otsu_filter.Update() + + result = otsu_filter.GetOutput() + + # TODO auto-serialize in objdir_wrap? + return helper.itk_to_vtkjs_image(result) + @rpc('segment') @helper.objdir_wrap def segment(self, image, point):