Problem with to calculated the prewitt

조회 수: 1 (최근 30일)
Cristina
Cristina 2011년 11월 6일
Dear colleague I have a problem to calculate a parameter of feature of a image. This parameter is calculated by means the sum of intensity pixels of orginal images where the filter prewitt is one between the total pixel that filter prewitt is equal a one for each regions of my images.
I try in matlab the following sentences:
PW=edge(L,'prewitt'); %L is the label matrix with all regions of my images
for k=1:num %num is the number of regions in L, In this case 47
ind=find(L==k);
li=length(ind);
for i=1:li
if(PW(ind)~=0)
cont(i)=cont(i)+1;
sum(i)=y2(ind);
end
end
end
but these sentences give a error. What is the problem? Could someone help me?, please.
Thank you vey much in advance
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 11월 6일
Related question by the same author: http://www.mathworks.com/matlabcentral/answers/20464-problem-with-generate-exterior-border-of-regions

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

답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 6일
"ind" will usually be a vector, and indeed you loop "i" over the length of that vector. But you access PW(ind) and since ind is generally a vector, PW(ind) will generally be a vector. Your test
if(PW(ind)~=0)
is thus an "if" applied to a vector. MATLAB does define the meaning of that: it defines the test as being true only if all of values in the vector are non-zero (true) . Supposing that does happen, then you increment cont(i) and then extract y2(ind)... which is generally going to be a vector result. You then try to store that vector in the single element sum(i) which is going to fail. And then you loop around and for the next value of "i", you make exactly the same test.
Inside the loop, your references to ind should probably be references to ind(i)
Note: using "sum" as a variable name usually results in program bugs, as "sum" is the name of an important and commonly used MATLAB function.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 11월 6일
You did not initialize suma anywhere. Before the loop, put
cont = zeros(li,1);
suma = zeros(li,1);
Walter Roberson
Walter Roberson 2011년 11월 6일
All of your cont values will be either 0 or 1. You set up your code that way. I do not know what you are expecting cont to count, so I cannot offer any suggestions.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by