Replace and add element under specific condition

1 回表示 (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 4 月 3 日
if i have this a (n,m) tow matrix A and B for example
A = [ 1 0 1 0 1
0 1 0 1 1
1 1 1 0 0
1 0 0 1 1
1 1 0 0 1 ]
B = [ 1 0 1 0 1
0 0 0 0 1
1 0 0 0 0
1 0 0 0 1
1 1 0 1 1]
I need function to do this steps
w = B(1,:) % extract first row
for k:1:size(w)
if there is one in w(k) then go back to Matrix A(1,k)
chick if there is a one's beside it >> true
set in Matrix B(k) these one's
for example B(3,:) is [1 0 0 0 0] then go back to A(3,:) = [1 1 1 0 0]
then we check if there are one's neighbors to that one >> if yes
then put the same number of one's beside the first one and update B(3,:)
so B(3,:) will be [1 1 1 0 0]
  • Note : can't we say B(3,:) | A(3,:) because for example
the B(end,:) = [ 1
1
0
1
1 ]
then we chick A(2,end) [0 1 0 1 1] >> we see there is a just one beside it so the update on the second row in B will be like this [ 0 0 0 1 1]
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 3 日
This is not clear

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2016 年 4 月 3 日
How about this, which uses morphological reconstruction:
marker = B;
mask = A;
C = imreconstruct(marker,mask, 4)
C =
1 0 1 0 1
0 1 0 1 1
1 1 1 0 0
1 0 0 1 1
1 1 0 0 1
  3 件のコメント
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 4 月 4 日
no Mr Walter the c(2,2) must be zero ,, because its not neighbor to the last one in this row ,, there is zero between them

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by