Example 2

How to do Image Recognition

covering the topics

what is a correlation
doing a correlation
scripting a correlation
optical correlaters

What is a Correlation

You probably know that a 2 dimensional correlation amounts pretty much to sliding an one image over another and plotting the amount of overlap of the images as a value to be plotted at the shift position. The convolution is the same thing with one of the images rotated 180° before doing the correlation. To actually cary out such a correlation it is handy do the job with Fourier transforms. To correlate an image A with image B, one multiplies the Fourier transform of one F(A) times the inverse Fourier transform of the other F(B) and finally taking the inverse transform of the result.

A collection of binary files containing the upper case letters have been put in a folder called "Tutorial files". These letters were created in AppleWorks drawing document using Helvetica type face and 48 font size. These were clipped one at a time and pasted into a CoherentOptics document (128 size) and saved as "lettersUC#1" to "lettersUC#26".

Doing a correlation

If we were to correlate a "P" (#16) with an "R" (#18) we could do the following.

Open document window in 128 size, and then click Binary file in the lower left corner. Now find "letterUC#16" and load it. Next click the enter 1-0 button to place the image into the big array. Click the Fourier button. At this point we should save the file. Select save Big File from the file menu, and name the file something like "P Fourier". Now load the binary file "letterUC#18" enter it and click the inv-Fourier button. Now go to the Combine menu and select big array x big file. In the dialog select the file you just saved. now click invFourier to see the result.

Notice that the histogram shows that the peak value is around 2.84 in some units.

You could have skipped saving the "P fourier" file by clipping ( C) the big file then loading the R and using invFourier as before. Now you can multiply what you see by the clipboard by using ( M) and then using invFourier again as before. Look on the Edit menu for these functions.

It is instructive to look at the 3-D plot (either on the Goodies menu or use G) plotting with the default setting gives the following.

The correlation of P with itself has a peak value only slightly higher at 3.0. While the correlation of R with itself is 3.73. The R has more area.

Scripting a correlation

This script will produce the same series of steps provided you set up the dialogs in five of the icons. Starting from the start icon the next icon needs to load "letterUC#16". The next icon needing information is the clip. Set it to clip to data connection and big array. The following blue icon should load "letterUC#18". Set the next clip icon to paste with a data connection the Big Array and using Multiply Big Array. The last icon can be set to the default settings. When you click on start you will see two more dialogs select NO just once.

 

The first clip icon
dialog

The second clip icon
dialog

 

Optical Correlators

All of this can be done at the speed of light by just shining light through some appropriate masks and lenses.

The arrangement above is a minimum schematic of an optical correlator. What is actually on each of the planes is not defined in the diagram. The Fourier transform lenses are ordinary lenses used so that the distance to the two planes on either side is just the focal length of the lens (not the distance to form an image). The letter P plane for example could actually be a transparency of the letter P. The center plane could also be a transparency of the Fourier transform of the letter R perhaps printed from the output of this program. Which raises the issue of what to put on the transparency.

One could put the real part as gray scale, the real part as black and white, the magnitude, the binarized phase on the transparency.

If you were to use the real part it would be wise to take the inverse transform of the real part of a transform of the letter R so that we can see what it is with which we are correlating. If you can make the real part by setting the imaginary part to zero. You see that you are actually correlating with both an R and an upside down R.

There are more difficulties (such a defining the zero level) to be overcome in the lab, but this is a start.