Replace and add element under specific condition

5 visualizzazioni (ultimi 30 giorni)
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]

Risposte (1)

Image Analyst
Image Analyst il 3 Apr 2016
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 Commenti
Firas Al-Kharabsheh
Firas Al-Kharabsheh il 4 Apr 2016
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

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by