Morphing

ZXNet echo conference «code.zx»

From Vitaly Vidmirov To Vasily Below 8 December 1998

Hello, hello Vasily! One day, in the chilly summer, something around (07-11-98/01:21:00) Vasily Below once wrote to All... VB> I have 2 pictures (namely in chunks). VB> Can someone give me an algorithm or formulas for implementation VB> morph? Here is the simplest algorithm for real-time morphing with bending: I haven’t tried to implement it, because I’m making it up as I go along ;) However, it should work... IR original image PC - received 1. You need to match the pixels of one picture to the pixels of another. 1.1 Place on the IR grid: O--O--O--O | | | | O--O--O--O | | | | O--O--O--O The letters "O" indicate reference points (grid nodes). 1.2 We do the same with the PC, but the grid here will no longer be straight, but deformed. Those. each IR square will turn into the corresponding "something" on the PC. You can do anything with the condition that the resulting polygons remain convex. O--O--O--O | O-O/---O O/| | | | | O-O--O---O 1.3 For each reference point, we calculate the direction and step of movement. xstep(i)=(dstX(i)-srcX(i))/n ystep(i)=(dstY(i)-srcY(i))/n where n is the number of frames. 1.4 Now we need to do something more difficult, namely find step of changing the color of the IR pixels so that in the end they turned into PC pixels. For this purpose, every deformedtransform the PC quadrilateral using texturemapping into an undeformed one, the dimensions of which coincide with the straight IR square. As a result, we will get something like the final the “reverse morphing” phase. 1.5 Find the color change step for each IR pixel: cstep(x,y)=(revC(x,y)-srcC(x,y))/n where: revC color of the corresponding pixel of the image from paragraph 1.4 1.6 This completes the pre-calculation phase. 2. We do morphing. 2.1 Moving anchor points xo(i)+=xstep(i) yo(i)+=ystep(i) 2.2 Morphing colors srcC(x,y)+=cstep(x,y) 2.3 Using the obtained texture map reference points, add this to the buffer. 2.4 Everything. display on the screen. As you can see, everything is very simple, but... slowly... Well, can you pull it? evil Vitalik AKA Dark/X-Trade