Source code for node_reconstruction

# This file is part of Sympathy for Data.
# Copyright (c) 2018, Combine Control Systems AB
#
# SYMPATHY FOR DATA COMMERCIAL LICENSE
# You should have received a link to the License with Sympathy for Data.

from sympathy.api import node
from sympathy.api.nodeconfig import Ports, Tag, Tags

from skimage.morphology import reconstruction
from sylib.imageprocessing.image import ImagePort


[docs] class MorphologicalReconstruction(node.Node): author = 'Mathias Broxvall' icon = 'image_reconstruct.svg' description = ( 'Performs morphological reconstruction from a seed image and mask\n' 'image. Values are spread from the seed values, as long as they are\n' 'greater than or lower than the mask (for dillation respectively\n' 'erosion)') tags = Tags(Tag.ImageProcessing.ImageManipulation) name = 'Morphological reconstruction' nodeid = 'com.sympathyfordata.imageanalysis.morphological_reconstruction' parameters = node.parameters() parameters.set_string( 'method', value='dilation', description='Morphological method (dilation/erotion)', label='Method', editor=node.editors.combo_editor( options=['dilation', 'erosion']) ) parameters.set_float( 'offset', value=0.0, description='Offset applied to seed image before reconstruction', label='Offset' ) __doc__ = description inputs = Ports([ ImagePort('Seed image', name='seed'), ImagePort('Mask image', name='mask'), ]) outputs = Ports([ ImagePort('Result', name='result'), ]) def execute(self, node_context): params = node_context.parameters seed = node_context.input['seed'].get_image() mask = node_context.input['mask'].get_image() result = node_context.output['result'] im = reconstruction( seed + params['offset'].value, mask, method=params['method'].value, ) result.set_image(im)