Lesson #4
Building
an Image Recognition System.
building the filter
using the filter
In this exercise we will build a filter which when we can use to recognize any of 6 different capital letters from our example file. The filter will be constructed by multiplying the Inverse Fourier transform of each of these letters by a lens function designed to focus a spot of light to a different spot. The six composites will be added together and the result changed into a phase only filter by dividing complex number at each pixel by the magnitude of its value. This is done to add some reality of the simulation as well as to improve the results. Devices that can represent the magnitude or the phase are common, but to display both at the same time is difficult. There is more information in the phase. This will be discussed some more after we build the filter.
If you have already set up some default settings for the direct propagation dialogs and the lens function dialogs this example will go easier. You may have discovered that each size of window has a different set of default values so you eventually will want to set up 8 different windows. For now we will just use the 512.
Open a 512 window and open a script window. Since we will be adding the parts of the filter to a clip we need to install a zero array into a clip icon and then build the focused letter described above and add the accumulation to the big array and save the result back to the clip icon the result should look like this to start with.
![]() |
You need to set up the blue file icon to read a series of binary files. Use the capital letters starting with #1. Upper clip should clip big array to data connection. The lower should paste big from data connection and add to big array. The branching icon should pass 5 times and branch on the 6'th pass; so enter 5 in the box. Set the final display icon to show real part. The only icon left that needs setting up is the lens icon. We are going to give it a batch file to read in sequence. Open a spread sheet program and set up a table 5 boxes wide by 6 tall. The first 3 columns can be zero. The last two columns are 6 number pairs (-120, 150), (120,150), (-120,0), (120,0), (-120,-150), (120,150). Save the table as text, or tab delineated text, and give it a descriptive name. |
The lens dialog and spread sheet should look like this.
![]() |
![]() |
Now run the script. If you forgot to set up any of the dialogs you will be reminded. You should have seen the letters A through F flash on the screen and a final image that looked like this.
![]() |
If this is what you got save the result as a big file called "6 letter phase only 512". If the whole process went too fast you can insert a view icon The filter that we have just constructed could be displayed on a phase only device that shifts the phase of the transmitted light depending upon the value of the pixel at that point. So one would probably change the display on the left by selecting phase in the display options at the top of the main window and choose to display the result on a small second screen which is connected through the video output of the mac. (Many macs are able to handle second screen without the addition of an internal card.) If you have such a device set up select Big Window from the Goodies Menu. This produces a controller dialog and a window duplicating the contents of the main window. The controller dialog permits you to change the size of the new window and to move its lower left corner to the coordinates that you type into the controller dialog. It may take some experimentation to find the correct setting to use. Until you have perfected the art of using an external device. We will just simulate the result. |
We will simulate displaying the letters on a amplitude device, and then propagating the light through a fourier transform system which would consist of a lens a gap and a second lens the gap and the focal lengths of the lenses is the same. The light then falls on the filter constructed above. The light that passes through this lens will preferentially be focused to any of six points the intensity depending upon how well the letter correlates with the images represented in the phase only mask.
Make a new 512 window (N)
a new script window and make the following.
The only series operation in this script is the first binary file input which is the letters used before. The two lens icons are identical to the display above except the batch checkbox is not checked. The same is true of the two direct propagation icons. The pause is long enough to see the result. The count to branch is set to branch after 5. (branch to nothing, just stops) The blue multiply by big file icon should be set to use the file you saved in the first part of the lesson. The yellow display icon should display the magnitude squared. You should see a different point picked out for each letter.
To see this more clearly connect a graph icon in the gap before the pause icon. Notice how small the difference between the E and F is.
To speed up the loop you can replace the three pink icons in the top row with a Fourier icon.
To see just what it is that you are correlating with in this image recognition system load the phase only filter that you have saved into the main window then multiply it by a lens function (not complex conjugate) then click invFourier. The letters are in outline form because of the emphasis that the phase only operation places upon the higher spacial frequencies. (the outer part of the fourier transform image) So the phase only filter gives especially sharp correlations.