Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
mika
mika il 5 Dic 2013
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.

Risposte (1)

sixwwwwww
sixwwwwww il 6 Dic 2013
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 Commenti
mika
mika il 7 Dic 2013
Modificato: mika il 7 Dic 2013
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 il 7 Dic 2013
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