Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to set that image to 0 (false) at those locations, instead of plotting a marker over them? That would break it apart.

1 次查看(过去 30 天)
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
How to set to 0 (false) at those locations, instead of plotting a marker over them? That would break it apart.
Any ideas, Help is much appreciated.
  3 个评论
mika
mika 2013-12-5
Hello sixwwwwww,
Replacing 1 by 0 on the image below to break it apart,
at those locations detected, instead of plotting a marker over them.

回答(1 个)

sixwwwwww
sixwwwwww 2013-12-6
try this:
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', 'LineWidth', 2, 'MarkerSize', 20 ) ;
title( sprintf( 'Matches for "%s" pattern', labels{pId} )) ;
set( gcf, 'Units', 'normalized' ) ;
set( gcf, 'Position', [0 0 0.4 0.7] ) ;
end
It will connect marker points and will show how different parts of image are separated
  4 个评论
mika
mika 2013-12-7
编辑:mika 2013-12-7
The yellow points are not a markers i mean by drowing it with paint that this squeleton can be break apart there for example(breaking apart can mean replacing 1 by 0 )
Any ideas,
thx.
sixwwwwww
sixwwwwww 2013-12-7
Following code going close to it but lines are crossing each other:
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] ;
spy(A) ;
plot( c, r, 'k', 'LineWidth', 3, 'MarkerSize', 20 ), hold on
set( gcf, 'Units', 'normalized' ) ;
set( gcf, 'Position', [0 0 0.4 0.7] ) ;
end
Maybe you try to find a way that they don't cross each other then you will get the figure as you need

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by