How do I prevent my variable from being overwritten?

조회 수: 4 (최근 30일)
vaishali
vaishali 2013년 9월 20일
편집: Ashish Uthama 2013년 10월 14일
from binary image like white color banana and background is black .I divided this in three part 20% ,60% and 20%Middle 60% part is used to measure width of banana.I have rows and cols coordinates; for each col (within 60%area) want to find width
[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);
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;
Desired P should be of size 1 x (length(columns))
  댓글 수: 1
Image Analyst
Image Analyst 2013년 9월 20일
I gave you more compact and efficient code below, but you chose not to use it. Tell why.

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

채택된 답변

Image Analyst
Image Analyst 2013년 9월 20일
Your d is getting overwritten at each iteration of the j loop. You need to have d(j) instead of just d. But you actually don't even need it at all to find the first and last white pixel on a line. Just use find() with the 'first' and 'last' option:
for row = n11 : n22
x2 = find(BW(row,:), 1, 'last');
x1 = find(BW(row,:), 1, 'first');
d1(row) = x2 - x1;
end
  댓글 수: 10
Image Analyst
Image Analyst 2013년 9월 22일
See if the file attached below does what you want.
vaishali
vaishali 2013년 9월 23일
sir, file is very useful for me. Thanks for helping me.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by