Problem with to calculated the prewitt

4 views (last 30 days)
Cristina
Cristina on 6 Nov 2011
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 Comment
Walter Roberson
Walter Roberson on 6 Nov 2011
Related question by the same author: http://www.mathworks.com/matlabcentral/answers/20464-problem-with-generate-exterior-border-of-regions

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 6 Nov 2011
"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 Comments
Walter Roberson
Walter Roberson on 6 Nov 2011
You did not initialize suma anywhere. Before the loop, put
cont = zeros(li,1);
suma = zeros(li,1);
Walter Roberson
Walter Roberson on 6 Nov 2011
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!