Find all the points inside a triangulation
8 views (last 30 days)
Show older comments
I am currently working on problem in which I am using delanauy triangles to warp and morph two images.
Say i have
%These are the points marked on two different images that are to be morphed....
im2_pts = [y2(:) x2(:)];
im1_pts = [y1(:) x1(:)];
%calculating the average shape...
avg_pts=[x_avg(:) y_avg(:)];
%Triangulation...
tri = delaunay(x_avg,y_avg);
%For each triangle in tri i will perform the action below...
%First Triangle's co-ordinates
t1_x = [ 2736 1882 2736];
t1_y = [ 2736 1060 1];
%Second Triangle's co-ordinates
t2_x = [ 2736 1933 2736 ];
t2_y = [ 2736 991 2736 ];
tri1 = [t1_x(:) t1_y(:)];
tri2 = [t2_x(:) t2_y(:)];
%calculating the affine transformation...
t_affine = cp2tform(tri1,tri2,'affine');
now to apply the transformation, i need to find out all points in the triangle tri1. I know i need to use tsearch for the same. But i am not sure how to use it.
Please do let me know how do i perform this action. Thanks !!!! :D
0 Comments
Answers (1)
Florin Neacsu
on 17 Oct 2011
Hi,
Given any triangle, defined by the coordinates of its vertices you can "easily" find the interior points. Have a look at barycentric coordinates. Define a barycentric coordinate system with the triangle's vertices. Then any point will have 3 coordinates say a,b,c. If they all are positive then the point is inside the triangle. If not, the point is outside.
Hope this helps. Regards, Florin
See Also
Categories
Find more on Read, Write, and Modify Image 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!