Dec 052017
 
Graphic Utility to combine two image files.
File MORPH02.ZIP from The Programmer’s Corner in
Category Printer + Display Graphics
Graphic Utility to combine two image files.
File Name File Size Zip Size Zip Type
EGAVGA.BGI 5554 4021 deflated
MORPH.DOC 8537 3792 deflated
MORPH.EXE 157232 62704 deflated

Download File MORPH02.ZIP Here

Contents of the MORPH.DOC file


MORPH Rel Alpha 0.02 (11/18/92)
Copyright (c) 1992, by David K. Mason

This is just a brief intro to get you going with Morph. It's not
a real document or anything. Note: this is still a fairly early
alpha version of this program... it's prone to crashing at
inconvenient times, so save your warping meshes in files on
a regular basis. I haven't worked on this program in quite a
while except to fix one last bug that had been sitting there since
March, and I probably won't get back to it for another long while.
Feel free to report bugs, but don't expect 'em to get fixed too
soon.

To run morph, you MUST have:
1) A VGA monitor (regular VGA is sufficient... morph works only
in 640x480x16 mode)
2) At least a '286
3) A mouse with a microsoft-compatible driver

To accomplish any serious work with this program, you SHOULD have:

1) A numeric coprocessor... it DRAGS without one

2) Plenty of XMS or EMS unless you're working with teeny pictures.
During the warping process, morph creates a buffer
big enough to hold one entire picture, in RGBa (32-bit)
form. That means 256000 bytes if you're working with
320x200 pictures, or 1,228,800 for 640x480, or 1,920,000
for 800x600, or 3,145,728 for 1024x768.
If this buffer won't fit in conventional memory, then
Morph will either stick the buffer in EMS, XMS, or in virtual
memory, wherever it can find the space.
If it uses virtual memory, this is going to slow things
WAY down. That's because the second pass of the warp
routine operates on a column of pixels at a time,
resulting in a lot of disk thrashing. (Several disk
accesses per column!)

To get started with Morph, type "MORPH ".
The files can be TGA (16, 24, or 32, compressed or uncompressed),
Vivid IMG, or GIF. The two files don't have to be in the same
format, but they do have to have the same dimensions.
Morph doesn't currently check to make sure they have the same
dimensions, so if you mix 'em up, you might get REAL odd results,
run-time error, or both.

The only type of output Morph creates is compressed Targa-32
files. VPIC and PICLAB have some trouble reading the output files,
because the run-length packets span lines.
DTA can read 'em okay, though.

Morph will then read and display the two pictures in side-by-side
windows. If you only gave one filename, then it'll display
that picture twice.
(It scales 'em so they'll fit in the windows. By default it
scales with a nearest neighbor routine. If you have MIPS to
burn, or don't mind waiting, you can get better-looking
images on the screen by using the command
"MORPH /SLOW (file1) (file2)"
and it'll scale them with interpolation instead.

Then, a mesh is laid over the two pictures.
In this program, a mesh is represented by a bunch of horizontal
and vertical lines. The points where they intersect can be
adjusted.
Initially, there are lines on the four edges of the picture,

There are always the same number of mesh points defined in the
two pictures, though they aren't always in the same places
unless the meshes are locked.

To add a new line to the mesh, move the mouse cursor to the
border around one of the pictures (which one doesn't particularly
matter). Click the button at the point where you want the line
added. (If the cursor is on the top or bottom border, a vertical
line will be added, and if it's on one of the sides, a horizontal
line will be added.)

To move a vertex, put the mouse cursor over the intersection
of two lines, press the button, and move the mouse.
Let go of the button when you've got the point where you want
it. Morph will try to prevent you from overlapping lines.
It's possible to defeat it with weird angles. It's best if
you don't, however.

Here's what the other controls on the screen do:

Lock/Unlock: If lock is selected, the two meshes are
synchronized. Move a point on picture #1, and the same
point in picture #2 will move too.
If unlock is selected, then the two meshes are independent.
I tend to keep the meshes locked at the beginning, while
I'm setting up points for picture #1. Then unlock and
move the points on picture #2 around.

Morph/Warp: In Morph mode, the program will map points from
picture #1 toward picture #2, and from 2 toward 1, and
cross-fade. In Warp mode, it'll just map points from
#1 toward #2, with no fade.
Not too surprisingly, Warp mode is takes half the time
that Morph mode does.

Lines/Splines: When your points are all located where you
want them to be, and you tell Morph to go ahead and morph,
Morph figures out which points to map where by (in Lines
mode) drawing lines between the vertices. In Splines mode,
it draws curved lines between the points.
Reasons to use Splines instead of Lines: the warp often looks
a whole lot better.
Reasons to use Lines instead of Splines:
(1) Splines sometimes go haywire, with curves going every which
way, overlapping, etc.
(2) You don't want something curved when it warps
(3) lines are faster than splines.

Smooth/dumb resampling: In smooth mode, Morph interpolates
new pixel values from all source pixels that should
contribute... in dumb mode, it just grabs a single pixel
value. Nearest neighbor, in other words. The results
in smooth mode look massively better than dumb mode.
But dumb mode is massively faster. Dumb mode would be
useful in test runs, but don't use it for real stuff, 'cause
it looks like crap.

The Frames control: tells Morph how many pictures to create.
If you're in Morph mode, then this represents how many tween
frames to create. In warp mode, this number includes a
fully-warped final frame.

The Splines button: gives you a preview of what splines for the
current mesh points would look like. If you're using Splines
mode, make sure you use this button once in a while to make
sure the splines aren't going nuts.

The Zoom buttons: display just one of the images, much larger.
This gives much finer control over the mesh control points.

The Save button: saves your meshes to a file.

The Load button: loads a mesh file. Type the filename right the
first time or you'll get a run-time error and get dumped out to
DOS.

The Go button: causes Morph to start morphing.

The Abort button: Changed my mind. Get me out of this program NOW.

If all this makes no sense, just start messing around with the
program. Once you figure out how to add new points to the mesh,
the rest of the interface is pretty intuitive.

Credits:

The warping and morphing algorithms come from George
Wolberg's book Digital Image Warping.
Unfortunately I had to work out most of the implementation
details myself.
The image scaling and spline code come virtually unchanged from the
same book (except for translating it from C to Pascal).
I ripped the line drawing routines off from PC Magazine's
book Turbo Pascal 6.0 Techniques and Utilities, by Neil Rubenking.
I don't remember what other places I stole stuff from.
Much is actually my original work, though.

Stuff I'm going to add or change (sooner or later):

1) Deletion of mesh lines.
2) A better way of adding mesh lines.
3) Proper handling of the alpha channel. Right now Morph takes
the alpha byte from TGA-32s into account, but I haven't
bothered to make it work with them right.
Since I don't actually have any test files with real alpha
info in them.
I'm also going to have to write a little program to add alpha
info to pictures (a seed fill to alpha out the background
is a method suggested in Foley & Van Dam).
And write a program to do compositing (or add that capability
to DTA).
By the way, I'm currently going under the assumption that alpha
represents transparency, not opacity. (In other words,
0 means completely opaque, and 255 means completely transparent.)
That appears to be the more common way of handling the alpha
byte. If anybody who reads this knows better, please fill
me in.
4) Eventually ... SVGA mode or modes... I'd particularly like
to do a 1024x768x256 mode, which'd allow two 500x500 (or
something like that) 64-gray images instead of 300x300 with 8
grays. Zoom-in would be REALLY detailed.

-- David K. Mason
P.O. Box 181015
Boston, MA 02118


 December 5, 2017  Add comments

Leave a Reply