keyword :warping Unit Square to Quadrilateral
input : จุดมุมในสีเหลี่ยมใดๆปลายทาง 4 จุด คือ (x0,y0), (x1,y1), (x2,y2), (x3,y3)
output : Transformation matrix และการทดสอบwarp จุด
% Unit Square to Quadrilateral % By Nemin Suksen % Master Degree FIBO, KMUTT, Thailand % Reference: pages 17-21 of Fundamentals of Texture Mapping and Image Warping, Paul Heckbert, % Master’s thesis, UCB/CSD 89/516, CS Division, U.C. Berkeley, June 1989, % URL=http://www.cs.cmu.edu/?ph. % Thank Nung Navakun Sebang for paper sample data and suggestion clc; clear all; close all; %% Source Quadrilateral % 4 Point of unit squre = (u0,v0), (u1,v1), (u2,v2), (u3,v3) u0 = 0; v0 = 1; u1 = 1; v1 = 0; u2 = 1; v2 = 1; u3 = 0; v3 = 1; %% Destination Quadrilateral % 4 Point of Quadrilateral = (x0,y0), (x1,y1), (x2,y2), (x3,y3) x0 = 10; y0 = 190; x1 = 310; y1 = 190; x2 = 310; y2 = 10; x3 = 10; y3 = 10; %% additional define for faster computaion dx1 = x1 - x2; dx2 = x3 - x2; sx = x0 - x1 + x2 -x3; dy1 = y1 - y2; dy2 = y3 - y2; sy = y0 - y1 + y2 - y3; if (sx == 0) && (sy ==0) % xy polygon is a parallelogram a = x1 - x0; b = x2 - x1; c = x0; d = y1 - y0; e = y2 - y1; f = y0; g = 0; h = 0; else den = dx1*dy2 - dx2*dy1; g = (sx*dy2 - dx2*sy)/den; h = (dx1*sy - sx-dy1)/den; a = x1 - x0 - g*x1; b = x3 - x0 - h*x3; c = x0; d = y1 - y0 + g*y1; e = y3 - y0 + h*y3; f = y0; end %% test point u = 0.5288; v = 0.0924; w = g*u + h*v + 1; x = (a*u + b*v + c) / w y = (d*u + e*v + f) / w |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น