Tutorial Example 3
Using the Scripting Tools
Displaying Binary Files With a Loop
Making a Series of Fourier Transforms
Depth of focus
Displaying Binary Files With a Loop
We will load and display all the letters contained in the folder "Cap letters 48 pt" using a loop.
Open a window having size 256 then click scripting. Make a script that looks like this. | ![]() |
Press the return button (or click Start). The blue icon is highlighted and a getFile window is opened for you. Navigate to the "Cap letters 48 pt" folder and select "lettersUC#1". As soon as you close the window you are asked if you wish to read the files in order. Pick "do series". Before the script continues you will be asked to set the display options. Choose "show hidden screen". Press the return button again.
It the main window was visible you saw the letters flash by on the screen very fast. (too fast)
Change the script to look like this. Press Return. Pause is now highlighted and you are asked to enter a time. Pick some reasonably short time like 0.3 seconds. Hide the window and press Return again. Don't forget to make the main window visible. | ![]() |
The loops above both stopped when the list of files was exhausted. So you may wonder what happens if the loop doesn't stop itself. Click the blue icon with the pointer cursor to open it. Select "lettersUC#1" as before but this time after selecting the file choose No just once. Now when you hit return the loop will continue forever. To stop the script click the single step checkbox. When this is checked the script will stop after each icon. You can advance one icon at a time by clicking the Continue button or by pressing the space bar.
Make the addition of the "bell" icon to the script. Make sure that the "lettersUC#1" is chosen and "do series" is chosen. Now when the loop is completed the script branches to the bell icon. But wait theres more! When the file list is exhausted, the file count is reset to the first value that you entered. So if you were to return to the icon by some rout the series will be repeated. |
![]() |
In this next script a "branch" icon has been inserted before the first file is loaded and the loop starts to execute. At the conclusion of the loop the flow now goes to the "branch" icon again. If the "branch" icon has been set to branch after 2 or more passes the flow of execution will return for a repeat loop. When the "branch" icon has run through its count the flow passes to the bell. | ![]() |
Making a Series of Fourier Transforms
Make a script that looks like the one at the right. The yellow icon acts like the enter 1-0 button in the main window. It is necessary to move the image from the screen, where the dark blue file getter put it, to the big array where a Fourier transform can be done. Double click on the dark blue icon select "letterUC#1" as before and then select "do series". Double click the light blue icon and in the size file window select "New Folder" make one named "temp folder" and name the file to be saved "fourierLetter#1". In the following window check "do series". | ![]() |
After running this script you should have a folder full of files. In the main window click Big Files (in the lower lift corner) and open one of the files in the "temp folder" and then click invFourier. You should now see a letter.
You can save a series of files using any of the save file icons. Recall that the save big icon used above, saves directly from the big array while the save binary and save TIFF, on the other hand, save from the screen, requiring you make sure that the image is on the screen before saving.
The script at the right for example could save a series of TIFF images of the Fourier transformed letters whether the image is the real part, or magnitude, or some other view, depends upon the setting of the yellow display icon. | ![]() |
We are going to construct a script which will examine the focus produced by a zonal lens. This involves creating a loop in which we make a lens function with a calculated focal length which we assume is illuminated by coherent plane waves after this light passes through out imaginary lens we calculate how the light will propagate over several distances in order to see how it focuses.
Step one is to drag a lens icon
onto the scripting screen and then opening the dialog
that sets its parameters. These parameters should be appropriate for you equipment.
If you know the wave length of light you are working with and the pixel spacing
and size of the light valve use those values, and calculate a focal length which
causes the phase oscillation to reach the Nyquist limit at the edges. Use the
formula on the zonal phase factor page.
If you are willing to go along with the default pixel separation of 42micron and a wave length of 514.5 nm then the appropriate "magic distances" are for N= 128 use f=438.9 mm., for N=256 use f=877.7, for 512 use 1755.4, and for 1024 use 3510.9 mm. The picture on the "Zonal Phase Factor" page is for 512 so I will continue with the setting shown there.
After the light passes through the lens we want to simulate propagation with
the DirectPropagation icon
which when opened has a dialog that somewhat
resembles the lens icon's dialog.
We are going to examine the focus at a series of distances scattered around
the focal length of the lens. To do this we need to create a text file containing
the distances we are going to use. So, open the word processor or spread sheet
of your choice. and make a column of numbers around the focal length 1755 mm.
For example one may choose
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810.
Save these numbers at text and with some meaningful name where you can find
it soon.
So open a 512 window and drag a zonal lens icon onto the script view and open it and set the values to match the above. Then drag icons to make something like this. Set the lens and direct propagation icons to look like that bellow. |
![]() |
Open all of the new icons by double clicking. If you don't do this, the program will open them for you when you try to run. Make them look like the examples bellow.
![]() |
![]() |
![]() |
Lens function |
Direct propagation |
View options |
After closing the direct propagation dialog you will be asked to select a batch file. Select the text file that you have just saved.
Now run the script. The 512 direct propagation takes some time so you will have plenty of time to watch the series develop. You may want to see an enlarged view of the focus spot. To see it you should open the direct propagation icon and change the "Pixel spacing P2" text field by adding an additional zero after the decimal point (0.0042) Now run the script again.
Notice that when the list of distances that are being read by the "Direct Propagation" icon is exhausted that the execution stops with that icon. If you were insert a green "alt line" to another icon such as a bell program flow will pass to this line, instead of stopping. The list of numbers is re-initialized so that if the flow of the program returns to the icon the list is re-used, much as the list of files was re-used in an earlier example on this page.
Some of the displayed results have a square array of dots. This is due to the
corners in our square lens. lets make it round with a mask. To make a nice round
disk on the screen we will use the Gaussian function on the
Goodies menu. Select this item enter 256 (whatever) then click
do it. Check the black & white option
at the top. Open the drawer. Now click on the histogram to produce a nice disk
on the main screen. Clicking near the bump on the right will produce a disk
that just fits on the screen. Save this as a binary file. Now add two icons
to the script between the lens icon and the direct propagation icon.
Set the first to load your new disk file and set the second to use logic on
the big array 1-0.
Now run the script. We can eliminate the need to generate the lens over and over by adding two clip board functions and rearranging the script to look like this.
Set the dialogs for these two new icons as shown.
![]() |
![]() |
The upper icon |
The lower icon |
The red line between the two clip icons is the data connection. Using this change we no longer load and enter the file on each pass around the loop after generating the lens and masking it we save the result to the upper clip icon which holds a copy of the big array and makes it available to the lower clip icon which loads the copy into the big array each time it is executed. We could have saved the array to a Big File on disk and then recalled it on each pass just as well but I like to do it this way.
Now run the script.
Try running the script with different sizes of disk and see the change in the quality of focus as well as the change in the depth of focus.
You will notice that the display on the main screen is always set so that the highest value is plotted as black, no matter how small it happens to be. If you add a graph icon to the script between the view and paste icons you can set the display graph to produce a height proportional to the value of the displayed quantity.
![]() |
![]() |
To watch the distances appear you can open the console window. The program outputs some information to the console as it runs. This is mostly useful to the programmer to test the programs execution. But some output has been left in the finish version of the program, mostly by accident. The direct propagation icon sends the distance it is working with to the console. You can find this program on the "Applications>Utilities" folder. Open it and, since it is full of output from all the programs running, you should clear it. Place the window in some spot where it won't be covered and run the script.