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.
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