Change element of a matrix in a row

1 visualización (últimos 30 días)
Selim Karakurt
Selim Karakurt el 3 de Nov. de 2016
Editada: Thorsten el 4 de Nov. de 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 comentarios
Jan
Jan el 3 de Nov. de 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 el 3 de Nov. de 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!

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 3 de Nov. de 2016
Editada: KSSV el 3 de Nov. de 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 comentarios
Selim Karakurt
Selim Karakurt el 3 de Nov. de 2016
Editada: Selim Karakurt el 3 de Nov. de 2016
for example something like this. all i want is to fill the picture with black.
Selim Karakurt
Selim Karakurt el 4 de Nov. de 2016
Nobody there to help me?

Iniciar sesión para comentar.


Thorsten
Thorsten el 4 de Nov. de 2016
Editada: Thorsten el 4 de Nov. de 2016

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by