Change element of a matrix in a row

1 vue (au cours des 30 derniers jours)
Selim Karakurt
Selim Karakurt le 3 Nov 2016
Modifié(e) : Thorsten le 4 Nov 2016
Hello community,
I am using matlab for image processing. I filter the image and get a black-white image and after that i want to count them. I finished that. The problem is that in the Matrix there are white places. For better understanding i gave you an example.
A
0 0 0 0 0
1 0 1 0 0
0 1 0 0 1
1 1 1 1 0
1 0 0 0 1
the result should be
A
0 0 0 0 0
1 1 1 0 0
0 1 1 1 1
1 1 1 1 0
1 1 1 1 1
I can't code it so please i need your help. I hope you can help me.
Thanks!
  2 commentaires
Jan
Jan le 3 Nov 2016
Please explain the procedure: Do you want to the rows to be filled by 1s between the first and the lase 1?
Selim Karakurt
Selim Karakurt le 3 Nov 2016
JES! I tried to give an example. But KSSV answer was good but it dont work because i have to change my logical matrix in to a double matrix. but when i do so my double matrix is filled with only 1 and i loose my information. you can look down what i talked with him. Thanks!

Connectez-vous pour commenter.

Réponses (2)

KSSV
KSSV le 3 Nov 2016
Modifié(e) : KSSV le 3 Nov 2016
A = [0 0 0 0 0
1 0 1 0 0
0 1 0 0 1
1 1 1 1 0
1 0 0 0 1 ] ;
B = A ;
[m,n] = size(A) ;
for i = 1:m
idx = find(A(i,:)==1) ;
if ~isempty(idx)
B(i,idx(1):idx(end)) = 1 ;
end
end
B
  6 commentaires
Selim Karakurt
Selim Karakurt le 3 Nov 2016
Modifié(e) : Selim Karakurt le 3 Nov 2016
for example something like this. all i want is to fill the picture with black.
Selim Karakurt
Selim Karakurt le 4 Nov 2016
Nobody there to help me?

Connectez-vous pour commenter.


Thorsten
Thorsten le 4 Nov 2016
Modifié(e) : Thorsten le 4 Nov 2016

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by