http://www.digitalmicroscope.com/dwn/vhx_2000_ka.pdf
shows some solid surfaces that were created of some relatively simple geometry from photos of mechanical parts, similar to threads on a screw. I wondered if the information in one of my stacks would allow a similar 3D surface to be constructed of insect features, specifically of a fly's eye, but I had many other things to pursue and put this investigation on the back burner.
A few weeks ago I was imaging the eyes of a colorful doli and decided to use the stack as a trial and to write some code to scan the fly and build a solid of the eyes. I budgeted 2 months to get the project done. Mostly because I did not want to be messing with software when fresh bugs emerge after winter.
I started out by teaching myself enough JAVA (computer programming language) to be able to decode the RGB data at each pixel of an image. Happily it turns out JAVA has most of the tricky bits built in and the online help is excellent so that was less of an obstacle than I had expected. My first baby step was to read a horizontal line of pixel values from one image and write out the RGB values into a text file. I imported the text file into Excel and looked over the changes in RGB values that occur in the focused areas and contrast that to the blurry areas. That allowed me to develop an algorithm to detect the center of a focus zone. The figures below are extracts from a small presentation I made for my work colleagues on this topic. (My colleagues think I am crazy but they enjoy the stories)








The method I chose to pick the center of the focus band is described here but poorly. Essentially I use a weighted average location with the threshold for focus detection set at 40. It worked well enough. I am sure that other methods could be chosen that would work better.

This shows the pixel locations that the algorithm has selected for the center of the focus band. I scan every forth line vertically (white spots) and vertically (black spots). I started scanning every line but the "point cloud" was excessive and so I chose to use fewer scans.

The program scales the pixel X-Y location to create X-Y coordinates in mm. In this case I have a 10X lens with my 3009X2009 pixel sensor and recon the width of a pixel to be .000788 mm. I calculated the step size between photos in the stack to be .005mm and used that to calculate the Z coordinate.
The JAVA program crunched through ~ 100 stacks on my old laptop in about 20 minutes. I consider that an acceptable stack time. The data file it produced is 7 MB.
I used my workstation at the office to crunch the 3D points and turn them into surfaces. I am a mechanical engineer and work with a variety of mechanical design modeling programs. For this task I used Unigraphics NX. I am hoping to discover a simpler lest costly program that could be used for this hobby as I can't allow my hobby to encroach on my work.
Here are some snips from the screen of the point cloud and the surfaces the computer created. Note that I trimmed away points from the doli's whiskers and antenna.

This slice of surface and point cloud shows the surface is well placed.

Both eyes... Each eye surface is separately modeled

In the drafting mode of the UG software, I can construct slices through the eye surface in arbitrary planes and project them. This tells me the male doli in the photograph has eyes with good range resolving capability when the prey or mate is relatively close by... Perhaps 1-2 body lengths. It will be interesting to compare the shape of the female fly.

I am still working on a editor to allow me to trim out unwanted point cloud areas near whiskers and antenna. For this analysis I had to do that manually in UG which was laborious.
Overall I am quite pleased with what I accomplished on the software side in a few weeks. Not a bad first effort.
What do you think?
Keith