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)
Mostrar comentarios más antiguos
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 comentarios
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?
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)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!