MovieDigitizer

A MathLink program for Image Processing
 of
 QuickTime File

Chikara MIYAJI
Institute of Health and Sport Sciences,
University of Tsukuba,
Tsukuba City, Ibaraki, JAPAN 305
miyaji@taiiku.tsukuba.ac.jp

Before you Start.

Mathematica version

Your Mathematica  must be version 2.2 or later for MathLink  connection. For MovieDigitizer,
your Macintosh system should be 7.0 or later.

QuickTime Extension

You must have QuickTime extension in System Extension Folder. Current version of QuickTime
is 1.6.1. MovieDigitizer will work with version 1.5 or later.

Enable Program Linking

If you want to connect MovieDigitizer through AppleTalk, 
you must start "program link" from the sharing setup in contorl panel .
Also, you must enable guest user to connect from the "users & groups" in  contorl panel.

Set MacTCP Properly

If you want to connect MovieDigitizer and Mathematica  through TCP/IP, you must
properly set MacTCP in control panel.
If you already done Mathematica  front end and workstation kernel connection, 
you should have already done it.

Listen or Connect

Both Programs, Mathematica  and MovieDigitizer, you can choose LinkMode
Listen or Connect. If one program is listening, other should be connect, and
listening program must be launch first.
This Listen/Connect procedure will apply both AppleTalk and TCP/IP connection.

Connect through AppleTalk

If both kernel and MovieDigitizer run on Macintosh, you can connect them
through PPC AppleTalk connection.

Run MovieDigitizer

When you run "MovieDigitizer", a dialog will appear like below.

LinkMode wolud be Listen or Connect.
You must Choose Link Protocol to PPC.
LinkName will  be some arbitrary name which matched Mathematica's argument.
Everything done, Click OK Button.

Connect MovieDigitizer from Mathematica

Connect "MovieDigitizer" with Mathematica  by Intsall command. 
The argument of Install command "MovieDigitizer" is the same
name which you set it in LinkName in dialog window.
LinkMode should be matched MovieDigitiger's LinkMode.

lnk = Install["MovieDigitize",
	LinkMode->Connect]

When Connect program can't find the Listen program

If connection program can't find the listening program to Link, for example,
listen program is running on the different zone, or simply name is different.
It will beep and ask you to find manually with the Dialog below.

You must choose apropriate program to link.
If connection success, LinkObject[....] will return.

connection through TCP/IP

If Mathematica kernel runs on Unix and MovieDigitizer runs on Macintosh, you can
 connect them through TCP/IP connection.

On Macintosh Side

Double click "MovieDigitizer". When it started, a dialog will appear like below.

LinkMode wolud be Listen or Connect.
You must Choose Link Protocol to TCP, and LinkName will  be some arbitrary number
greater than 5000. 
Then, click OK Button.

On Unix Side

To identify Macintosh as TCP/IP domain, you must set LinkHost properly.
It will be the name of Macintosh which  registered in DNS(Domain Name System)
or /etc/hosts file. Or you can put IP Address of the Macintosh directly.
"5000" is the TCP/IP port number which MovieDigitizer is listening. If you want to
change this number, you must change the number in MovieDigitizer's dialog also.

lnk = Install["5000",LinkHost->"130.158.112.209",
LinkMode->Connect]

If connection success, LinkObject[....] will return.

Open QuickTime File

Before issue QT commands, you must open some QuickTime File from MovieDigitizer program. Just select FILE menu Open. It is normal Macintosh Open procedure.
After Open QuickTime File, you can view and move frame by Movie Contorol bar.

The Commands of MovieDigitizer

QTGet[]

QTGet[] will return the coordinate of the point where you click 
the mouse.
[1] issue QTGet[] command,
[2] you'll move to MovieDigitizer window, the mouse cursor
will change to cross-hair. And you'll see (x,y) value down
below the window.
[3] Where you click the mouse, the {x,y} coordinate of that
point will return to Mathematica. as list.

The origin of coordinate system is top left corner of the window.

QTGet[]

QTPix[{x,y},{x,y}]

QTPix[{x,y},{x,y}]will return the Raster Array format of the area {x,y}
and {x,y}. The format is completely compatible to RasterArray.
So, if you use QTPix with QTGet like below, you can copy Raster
Image from QT file to Mathematica.
Be carefull the size of rectangle. For example,
if the arguments of QTPix is [{0,0},{100,100}], each dot contain three integer RGB value,
so the number of integer return from MovieDigitizer will be 30000!!(100*100*3).
Also, notice, when the QT window is covered by some other window,
and you choose the area where covered by some other window,
QTPix and QTimage will return the image of covered window, not the QT
file image.

Show[QTPix[QTGet[],QTGet[]]]

QTImage[{x,y},{x,y}]

This is similar to QTPix but it return only RGB number as list of list.
The List of RGB will start from left bottom of area, to right,
then move up to one line.....
{{{r,g,b},{r,g,b},....{r,b,g}},
{{r,g,b},{r,g,b},....{r,b,g}},
....
{{r,g,b},{r,g,b},....{r,b,g}}}

area = QTImage[{0,0},{10,10}]

Image2Pix[image]

You can convert Image format to RasterArray foramt.

Show[Image2Pix[area]]

QTStep[n]

You can move around movie frame. QTStep[n] moves movie n frame.
If n is negative, movie will move backward. If n is zero, movie will move to start.

Do[QTStep[1],{i,5}]

To Finish MovieDigitizer

Uninstall[lnk]