Source code for node_labelling

# This file is part of Sympathy for Data.
# Copyright (c) 2017, 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 import morphology
from sylib.imageprocessing.image import ImagePort


[docs] class ImageLabelling(node.Node): name = 'Label image' icon = 'image_labelling.svg' # description = ( 'Creates integer image with separate labels for each connected ' 'region with same values in input image') nodeid = 'syip.labelling' tags = Tags(Tag.ImageProcessing.Segmentation) parameters = node.parameters() parameters.set_boolean( 'diagonal', value=False, description='Allow connections along diagonal', label='Diagonal neighbourhood') inputs = Ports([ ImagePort('source image to label', name='source'), ]) outputs = Ports([ ImagePort('result after labelling', name='result'), ]) def execute(self, node_context): params = node_context.parameters image = node_context.input['source'].get_image() im = morphology.label( image, connectivity=2 if params['diagonal'].value else 1) node_context.output['result'].set_image(im)