필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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
vaishali
vaishali 2013년 9월 20일
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
Image Analyst 2013년 9월 21일
편집: Image Analyst 2013년 9월 21일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 20일
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
vaishali
vaishali 2013년 9월 20일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by