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
Mostra commenti meno recenti
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 Commenti
Matt Kindig
il 20 Set 2013
You didn't ask a question. Also, can you illustrate what you are trying to do?
Image Analyst
il 20 Set 2013
Modificato: Image Analyst
il 20 Set 2013
So do you just want the number of rows between the top row and the bottom row (where rows means only rows that have any number of 1's in them)? Or do you want to find the distance between the two most distant points anywhere in the image? Or the distance between two most distant points where one point is in the top and the other point must be in bottom row? This is ambiguous so please clarify.
vaishali
il 20 Set 2013
Image Analyst
il 21 Set 2013
Modificato: Image Analyst
il 21 Set 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?
Risposte (1)
Azzi Abdelmalek
il 20 Set 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 Commento
vaishali
il 20 Set 2013
Categorie
Scopri di più su Operators and Elementary Operations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!