I am getting error for this code for edge detection in hsv image
1 view (last 30 days)
Show older comments
I am finding the edge based on the triangle similarity In this it is assume that along with the change of the triangular shape, color is changing, the essential of triangular shape change is the value of h, s and v changed, it is the root cause of color changes.
The sides of triangle ABC
respectively is AB=h, AC=s, BC=v,
perimeter is L=h+s+v.
θ1=acos(( s^2 − h^2 − v^2)/2*h*v )
θ2 =acos(( h^2 − s^2 − v^2)/2*s*v)
θ3=acos(( v^2 − h^2 − s^2)/2*h*s)
So each pixel in the image will be plus one in edge detection processing in order to ensure that each pixel can construct triangle according to its r, g and b component, it will not make any effect to final detection results.
I=Lθ , r, g and b is the coordinate of that point
in HSV space.
Is this code right for this algorithm as I am getting right
Algorithm is given here
a) Each pixel value in the image will plus one;
b) Building corresponding triangle of all pixels and calculating triangular perimeter and three angles;
c) For each pixel, Sobel operator in four directions template and neighborhood pixel convolution, and calculate angle and perimeter difference;
d) Compared triangle perimeter corresponding with neighborhood to original triangle perimeter, if the difference is more big, so make the value of pixel is one, otherwise turn to e;
e) If the difference of triangle perimeter is not big, but the difference of corresponding angle is large, so make the value of pixel is one, otherwise turn to f;
f) If the difference of triangle perimeter and angle are both not very big, but they keep poor in threshold requirement range, so make the value of pixel is one, otherwise make it is zero to detect the image edges.
Because I=L calculate is larger, the actual implementation process is separately apply L and , if L is larger, then use L as the criterion of whether pixel is edge points; otherwise use .
function[e]=tedge(hsv)
h=hsv(:,:,1);
s=hsv(:,:,2);
v=hsv(:,:,3);
for i=1:183
for j=1:276
h(i,j)=h(i,j)+1;
s(i,j)=s(i,j)+1;
v(i,j)=v(i,j)+1;
end
end
L=h+s+v;
a1=acos((s.^2.-h.^2.-v.^2)./2.*h.*v);
a2=acos((h.^2.-s.^2.-v.^2)./2.*s.*v);
a3=acos((v.^2.-h.^2.-s.^2)./2.*h.*s);
a=a1+a2+a3;
I=L.*a;
Th=0.4;
w0=[-1,-2,-1;0,0,0;1,2,1];
w90=[-1,0,1;-2,0,2;-1,0,1];
w45=[-2,-1,0;-1,0,1;0,1,2];
w135=[0,-1,-2;1,0,-1;2,1,0];
for i=1:3
g0=imfilter(a,w0(i));
g90=imfilter(a,w90(i));
g45=imfilter(a,w45(i));
g135=imfilter(a,w135(i));
end
if L>=I
for i=1:size(L,1)
for j=1:size(L,2)
L(1)=L(i-1,j+1)+2*L(i,j+1)+L(i+1,j+1)-L(i-1,j-1)-2*L(i,j-1)-L(i+1,i-1);
L(2)=L(i+1,j-1)+2*L(i+1,j)+L(i+1,j+1)-L(i-1,j-1)-2*L(i-1,y)-L(i-1,j+1);
L(3)=L(i,j+1)+2*L(i+1,j+1)+L(i+1,j)-L(i-1,j)-2*L(i-1,j-1)-L(i,j-1);
L(4)=L(i,j+1)+2*L(i-1,j+1)+L(i-1,j)-L(i+1,j)-2*L(i+1,j)-L(i,j-1);
end
end
if L(1)>Th
e=L(1);
else if L(2)>Th
e=L(2);
else if L(3)>Th
e=L(3);
else if L(4)>Th
e=L(4);
end
end
end
end
end
x0=abs(g0);
y90=abs(g90);
x45=abs(g45);
y135=abs(g135);
for i=1:4
Ga1=sum(x0(i));
end
for i=1:4
Ga2=sum(y90(i));
end
for i=1:4
Ga3=sum(x45(i));
end
for i=1:4
Ga4=sum(y135(i));
end
if a>=I
if Ga1>Th
e=Ga1;
else if Ga2>Th
e=Ga2;
else if Ga3>Th
e=Ga3;
else if Ga4>Th
e=Ga4;
end
end
end
end
end
Error
??? Output argument "e" (and maybe others) not assigned during call to
"C:\Users\Poonam\Desktop\MATLAB\R2008a\tedge.m (tedge)".
Have i done something wrong in the code
0 Comments
Accepted Answer
Walter Roberson
on 22 Feb 2013
You have L=h+s+v; so L is a vector. But you also have
if L>I
which is then attempting to apply "if" to a vector of results. What are you expecting to have happen if only some of the L are greater than the corresponding I ?
Also, I see a multiplication used to produce I from L, but suppose an L item was 0, then the result of the multiplication would be 0, and that would be equality not ">". Did you take that into account when answering about if only some of the L are greater than the corresponding I ?
2 Comments
Walter Roberson
on 23 Feb 2013
If your new code is what is above, then right after the "for i" loop that has the imfilter, you still have
if L>=I
More Answers (0)
See Also
Categories
Find more on Solvers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!