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 日間)
mika
mika 2013 年 12 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.
mika
mika 2013 年 12 月 6 日
Or can we break apart that image where every region contain a marker ?
help please !
thx

回答 (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