Skip to content

Commit

Permalink
Add rpc that otsu-thresholds with tubetk
Browse files Browse the repository at this point in the history
  • Loading branch information
HastingsGreer committed Jan 25, 2019
1 parent 9e8346b commit df7561c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Binary file added server/__pycache__/helper.cpython-36.pyc
Binary file not shown.
Binary file added server/__pycache__/protocol.cpython-36.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions server/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
18 changes: 18 additions & 0 deletions server/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit df7561c

Please sign in to comment.