003.m1
Mathematica Note
I use Mathematica to maintain virtually every aspect of this website, from authoring the text to generating the final HTML pages. But one area I hadn't initially expected to use it for extensively is the image processing involved in going from raw camera images of the samples to the multiple sizes and types of images used on my site.

I had always used tools like GraphicConverter for that kind of thing, and I still do for some operations. But once I went to the current design, in which each sample image can be displayed in literally 30 different possible sizes, I needed a much more programmable system, so I turned to, what else, Mathematica.

For simple image scaling, I use Mathematica to call command-line UNIX image utilities, but when it came time to create the odd-even interleaved images necessary to see stereo images using special LCD shutter glasses, I decided the only practical alternative was using Mathematica's JPEG import/export functions to read the images in, interleave them, and then write them back out again.

I shouldn't say it, but I was expecting this to be slow.... But it turns out that with the improved import/export functionality and support for very efficient packed array data structures in Version 5, it's actually quite practical to read in large images, process them, and write them back out again. It's also incredibly simple. Here is the complete text of the Mathematica program necessary to read in, interleave, and write back not just one pair of images, but a whole directory full, including the special case of interleaving the first and last two images to make a seamlessly-rotatable set of interleaved images:

InterleaveImagePair[{file1_, file2_}, fileOut_] := Module[{g1, g2, imagePair},
    g1 = Import[file1];
    g2 = Import[file2];
    imagePair = {g1[[1,1]], g2[[1,1]]};
    Export[fileOut,
        ReplacePart[g1, Table[imagePair[[Mod[i, 2, 1],i]], {i, Length[imagePair[[1]]]}], {1, 1}]];
]

InterleaveFrameList[indir_, outdir_] :=
    Map[InterleaveImagePair[#, StringReplace[#[[1]], indir -> outdir]] &,
        Partition[FileNames["*.JPG", {indir}], 2, 1, {1, 1}]]

I challenge anyone to find a language or program where this is easier to do! To see the result of this applied to the lithium oxide crystals pictured here, click here. Note that if you don't have LCD shutter glasses, you may not fully appreciate the point of this. Click the "3D Help tile for more information.
003 Lithium