Morph one image into another?

BlitzMax Forums/BlitzMax Programming/Morph one image into another?

Curtastic(Posted 2007) [#1]
Does anyone have a function to smoothly morph one image into another? Kind of like the terminator but not turning silver?

I need it to take into account a passed scale and color along with the original image. Images also have a single background color.

I need to draw the image as it morphs ideally at 35 FPS and it should take 1 or 2 seconds and not lag my game too much. Images size only about 30x50

Thanks


Robert Cummings(Posted 2007) [#2]
.


Robert Cummings(Posted 2007) [#3]
I would suggest you get a morphing program, freeware or something and prerender the stuff?


Vertex(Posted 2007) [#4]
Morphing based on to operations:
Alphablending and "Morphing"

Alphablending is clear and the morphing is based on a net of triangles. You define significant points(like eyes, nose, corners of the mouth, brows etc.) and your program should compute around these points a net of triangles. These defined points have to set in start and end image. So you can interpolate between start and end positions of these points. The stretching and alphablending making the known morphin effect.

The hardest part is, to compute the net of triangles based on the given points.

cu olli


tonyg(Posted 2007) [#5]
You can try simply drawing both images and slowly increase the alpha on one and decrease the alpha on the other.
The alternative is to pre-morph BUT that's either a lot of
frames or impossible with large number of from/to morphs.
Not sure what effect you are really after but I thought about changing image1 to a single colour using code from here then expanding it into and ellipse before shrinking it to the new images size, displaying the new images as a single colour then fade to normal colours.


ImaginaryHuman(Posted 2007) [#6]
Yah you'll need your own textured polygon routine for each part of the grid.

You start out with either a regular # grid or one that you've positioned some points to align with certain features, then you are basically interpolating from the position of each point to its position in the destination image - which may or may not be a modified grid. You just need to figure out how far away the two points are in X and Y and then you need what is basically a `line draw` routine without the drawing part - look at the code archives at my integer line draw bresenham code. You step along the line for each frame - and you do so in total steps/length of line sections.


Curtastic(Posted 2007) [#7]
Thanks for the suggestions I should have realized I needed it dynamic, I can't really prerender becuase there are so many images that can morph to eachother. I thought this would be easier.

I just made each pixel an object and had each one move to a random target position of the new image. But ofcourse it looks like sand now. Any ideas on how to make it look more like goo?



tonyg(Posted 2007) [#8]
How about :
A bounding box utility where you specify, say, 6 points around each image which would morph and save them in a file to be read in when the image is loaded.
The morph then reads the source position and plots a course to the target position drawing them with SetUV.
It *might* be possible to dynamically find these points using either hull algo or simple line to point collisions.


PantsOn(Posted 2007) [#9]
just done this.... its not pefect.
I'll post up some code when I'm happy with it.
(its all real time morphing)




PantsOn(Posted 2007) [#10]
output is a lot better now


going to have to finalise the morph file format and then I'll release it


Curtastic(Posted 2007) [#11]
PantsOn: that looks good, does it also work with a single background color and images that are very different?

like this to this

No I'm not doing a frog-to-prince game! hmmm actually I could add that..


Tonyg: That sounds hard anyone wanna code it for me?:)

This seems a lot harder than I thought and I don't want to spend more time coding on it, its okay I'll just use the code I posted, thanks everyone for the help.


PantsOn(Posted 2007) [#12]
it can do any shape you want to any shape
(I've not tested it on large images)

but here you go...

(excuse the white background, but it will morph the alpha channel in realtime as well)

Before i release it, I'm going to make a gui for it.
I'll probably do that tomorrow.


Curtastic(Posted 2007) [#13]
wow that looks good!


PantsOn(Posted 2007) [#14]
sorry for the delay... the editor is taking longer than expected.
The gfx lib took 2 hours to write, the editor has taken a good 8 hours and still not finished. Typical ;-)

I'm going to make a very basic editor tonight (chop down what I got) and realease this baby ASAP.


ImaginaryHuman(Posted 2007) [#15]
With this kind of thing, positioning the grid well is harf the challenge, besides the morphing routine itself. That strip by PantsOn is a little off because you see the feet of the frog seeming to only fade out in a cross-fade and not actually move into the shape of the character. It's getting things to move well that is the key. But this look like it's coming along pretty well.


tonyg(Posted 2007) [#16]
It seems to use alpha and scale to make the morph which can look very good and is a good, simple solution if acceptable (it's what I would use).
'Real' morph is going to be more difficult.


PantsOn(Posted 2007) [#17]
it uses crossfading while moving a mesh... certainly not perfect, but quite fast.

It does look better the more detailed the mesh. currently I'm using a 4*4 mesh. The enegine allows any size mesh.

I wouldn't know where to start to do propper morphing..
didn't DpaintIV use 'propper' morphing in its day and not cross fade?

I'll do some research. ;-)


PantsOn(Posted 2007) [#18]
module released here
http://www.blitzbasic.co.nz/Community/posts.php?topic=71043