Draw a triangle in image knowing its center of gravity
4 次查看(过去 30 天)
显示 更早的评论
i need to draw a white triangle in a black image. So the first idea that i had got is to define the three peaks that define the triangle and then recuperate the points that belong to its surface. and then affect the value 1 to these points in a black image. To recuperate the points belong to the surface of the triangle i write this code which reflects the idea that a point belongs to a plan it verifies an equation system like after: ( the plane will be the triangle)
if true
k=1;
for i=1:size_image_x
for j=1:size_image_y
equation_x=i-x_peak1==xk*(x_peak2-x_peak1)+yk*(x_peak3-x_peak1);
equation_y=j-y_peak1==xk*(y_peak2-y_peak1)+yk*(y_peak3-y_peak1);
eqx=solve(equation_x,xk,yk);
eqy=solve(equation_y,xk,yk);
if isempty(eqx)~=1 && isempty(eqy)~=1
point_x(1,k)=i;
point_y(1,k)=j;
k=k+1;
end
end
end
end
but it doesn't work
may any one help me please
thanks
0 个评论
采纳的回答
Image Analyst
2015-4-17
Way too complicated. Simply use poly2mask() and do it all in one line of code:
mask = poly2mask([x_peak1, x_peak2, x_peak3], [y_peak1, y_peak2, y_peak3], size_image_y, size_image_x);
2 个评论
Image Analyst
2015-4-17
You need something else, like the radius and angle to one of the vertices or something. Obviously you could just spin a triangle around the center of gravity and they would all be triangles, just at different orientations. It's just a matter of simple trigonometry to get the three vertices once you have enough other information. What orientation do you want to draw it at? Surely you must have SOME idea.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!