# MATLAB: How to divide a skeleton into regions based on labels after detecting them in order to connect these regions to determine all the possible paths to matches extremities

binaryfeatures pointsImage Processing Toolboxmatchespathsskeleton

Is it possible to divide that skeleton below :
 to a set of regions based on labels below :X=[1 0 1 ;   0 1 0 ;   1 0 1 ;];Y=[1 0 1 ;   0 1 0 ;   1 0 0 ;];O=[0 1 0 ;   1 0 1 ;   0 1 0 ;];-=[0 0 0 ;   1 1 1 ;   0 0 0 ;];L=[1 0 0 ;   1 0 0 ;   1 1 1 ;];
after detecting them using this code :
 n = 50 ; A = double( rand(n, n+1) > 0.5 ) ; B = 2*A - 1 ; patterns = {[1 0 1; 0 1 0; 1 0 1]; ... % X             [1 0 1; 0 1 0; 1 0 0]; ... % Y             [0 1 0; 1 0 1; 0 1 0]; ... % O             [0 0 0; 1 1 1; 0 0 0]; ... % -             [1 0 0; 1 0 0; 1 1 1]} ;   % L labels   = {'X', 'Y', 'O', '-', 'L'} ; matches  = cell( size(labels )) ; for pId = 1 : numel( patterns )     nel    = numel( patterns{pId} ) ;     ker    = 2*patterns{pId} - 1 ;         [r, c] = find( conv2(B, rot90(rot90(ker)), 'same') == nel ) ;     matches{pId} = [r, c] ;     figure(pId) ;  clf ;  hold on ;     spy(A) ;     plot( c, r, 'r+', 'MarkerSize', 20 ) ;     title( sprintf( 'Matches for "%s" pattern', labels{pId} )) ;     set( gcf, 'Units', 'normalized' ) ;     set( gcf, 'Position', [0 0 0.4 0.7] ) ; end
in order to connect these regions:
1)for every extremity how to determine all the possible paths to matches extremities
2)for every extremity how to determine the paths which verify a configuration of the set of patterns .
here is the source image to perform tests :