# BW is binary image want to find distance between first row having '1' and last row having '1' from column n11 to n22 from following code.from this code result obtained is from column 1 to n22,but desired result should be from column n11 to n22

1 visualización (últimos 30 días)
vaishali el 20 de Sept. de 2013
BW=[0 0 0 0 0 0;1 1 1 1 1 0;0 1 1 1 0 0;0 0 0 0 0 0];
[rows, cols] = find(BW == 1);
n1=min(cols); n2=max(cols);
m1=min(rows); m2=max(rows);
column = n1:n2 ;
a=length(column);
b=a*0.2;
n11=round(n1+b);
n22=round(n2-b);
a1=horzcat(rows,cols);
columns = n11:n22 ;
for ii=n11:(n22);
for j=m1:m2
[row1 col]=find(BW(:,ii)==1) ;
x2=max(row1);
x1=min(row1);
d=x2-x1;
end
d1(ii)=d;
end
P=d1;
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
vaishali el 20 de Sept. de 2013
the distance between two most distant points where one point is in the top and the other point must be in bottom row in the same column.
_getting result_ P=[0 1 1 1]%%from col 1 to n22. Here n22=4
*desired result* P=[1 1 1]%%%for cols 2,3 & 4. n11=2 to n22=4
P should be 1x3 matrix but getting P<1x4>matrix
Image Analyst el 21 de Sept. de 2013
Editada: Image Analyst el 21 de Sept. de 2013
I didn't understand any of that. Try again. What is P? Please attach your image. You say "the distance between two most distant points where one point is in the top and the other point must be in bottom row in the same column" -- well if they're in the same column, but just in different rows (top row and bottom row) then why isn't it just the subtraction of the rows? Can you explain that to me? For example if I have a 1 in column 42 in row 10, and a 1 in column 42 (same column, as you said) of row 40, then why isn't it just 40-10 = 20 rows as the distance???
Anyway, let's say that really smart and perceptive person actually understood what you want, and gave you code for it. What do you want it for? What is the higher level goal of this hard-to-understand algorithm?

Iniciar sesión para comentar.

### Respuestas (1)

Azzi Abdelmalek el 20 de Sept. de 2013
BW=[0 0 0 0 0 0;1 1 1 1 1 0;0 1 1 1 0 0;0 0 0 0 0 0];
n11=1;
n22=5;
s=BW(:,n11:n22);
id=find(any(s,2));
d=id(end)-id(1)
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
vaishali el 20 de Sept. de 2013
BW binary image like horizontal banana white color and background is black .I divided this in three part 20% ,50% and 20%.50% middle part is used to measure width.I have rows and cols coordinates and for each col (within 50%area) want to find difference between top & bottom of the banana.

Iniciar sesión para comentar.

### Categorías

Más información sobre Images 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