.0 This example shows the specific steps taken in the Flatten Illumination Demonstration, and illustrates image transposition, image smoothing, image arithmetic, and multiple intensity profiles. Although this image is not a micrograph, it shows a large gradient in illumination or background intensity that sometimes plagues micrographs.
If desired, clear the screen and the memory using the MLx -> Pixel Array Ops -> Erase Everything command.
If desired, set auto_display to ON.
Invoke the MLx -> Parameters command.
Double click on auto_display, or select it and click 'select'.
Double click on 'ON'.
Click on 'Done'.
Now, the results of loading the image or of calculations will be displayed automatically.
Then load the Betsy Shipwreck.tiff image (Broadwater 1994). A quick way to find this image is to display this file: (edx "CCL:MLx Demo;flatten illumination;about Betsy shipwreck") by double clicking to either side of the expression above and typing apple-E, or, using the File -> Open MLx - Demo command to open the "About Betsy Shipwreck" text file, which is in the Flatten Illumination folder.
Use command-D or invoke the DBMac -> Defaults -> Top Fred command to set the default folder to the current folder.
Then use the DBMac -> Defaults -> Set Image Dir command to set the default image folder also to this folder, because the desired image is here also. (Often the images and associated code or text files are in different places, which is why two different defaults are used. Note that the default image folder is also controlled by the x_image_dir parameter, accessible via MLx - Parameters command.)
Finally, load the image with the MLx -> Image Files -> Tiff -> Read command. All of the above just saves hunting around for the image file when invoking the last command.
If only one image file is to be loaded, then holding down the command key while invoking the read menu saves one step. That step is to select a group of files in the folder to load. In this case, it is not necessary because there is only one .tiff file in the folder.
If auto_display has been turned on (see above), then the image of the interior of the hull of the ship will be displayed on its side. This is because the image was stored by a program array column-major-order rather than row-major-order, as LISP reads arrays (Steele, 1990). This situation occurs commonly when transferring images from one computer system to another, and so the image was left as-is for this example. Erase the image window, either by using command-W, or clicking on the go-away box at the left side of the title bar.
(Optional) Correct the appearance of the image by transposing the
image array with the MLx -> Pixel Array Ops -> In Place -> Transpose command.
This is one of the few commands that do not generate a new array, but simply
replace the old one (auto_display will not work here). Wait until the cursor
changes back from the stopwatch to the arrow, and the bottom of the Listener
window says 'idle'. Display the image using the MLx -> Show Image Arrays
command.

The image cannot be contrast enhanced because the gray levels in the image already cover the full brightness range, due to the large brightness gradient. To illustrate this, try enhancing the contrast with the Contrast Slider. The contrast slider is accessed by option-double clicking on the threshold slider until the bar appears gray. Use the MLx -> Threshold Slider command.
Option-double-click on the slider until the color bar is gray. The option key makes double clicking cycle between different slider modes: threshold, thermal, contrast, and CHI thermal. With no key held down, double-clicking toggles between an active slider and an inactive slider (image back to original, slider bar is light gray).
Click on the 'go away' box of the slider window to restore the image to its original appearance.
In order to subtract out the brightness gradient, it first must be extracted from the image. Do this with the MLx -> Pixel Array Ops -> Special - Fast Mean Filter command, and a kernel size of 41x41. Replace the default name of the result with something shorter, such as 'bkgnd'. Specify 'Int' as the output array type, as the additional precision of floating point is not need here. Smoothing will take a few seconds. Display using the MLx - Show Image Arrays command.
Note that the original image and especially the BKGND image have
a banded appearance, if the 'Monitors' control panel (in the Finder) is
set for 256 colors. This is because MacLispix uses the system palette all
of the time, and, for 256 colors, there are only 16 levels of gray available
- the rest are pastels and colors. To view the images properly, set the
Monitors control panel to 256 Grays (shades of gray) or to Thousands or
Millions of colors, if available.

The following instructions in blue are out of date. See more up to date
instructions for flattening illumination.
The BKGND image must now be subtracted from the original. Note, however
that it is smaller than the original by a 20 pixel margin. The margin is
deleted because the pixels of the smoothed result are not defined within
the radius of the kernel of the edge of the image. In this region, the smoothing
kernel (a 41x41 pixel square) lies partly outside of the image, and therefore
is lacking data. (No scheme has yet been implemented in MacLispix to extrapolate
the edge data.) The original Betsy Shipwreck image must thus be trimmed
to match the BKGND image. Do this with the MLx -> Pixel Array Ops -> Special
- Crop for Kernel command, using the 41 pixel width and height which are
now the defaults. (Crop the original image and not the background image.)
Delete some of the default name for the cropped image to make it 'BETSY_CROP'.
Using command-I, note that the new cropped image has the same dimensions
as the background image. This is required to make the difference image.
Subtract the BKGND image from the cropped original, BETSY_CROP with
the MLx -> Pixel Array Ops -> Real Arithmetic command. Select '-' for the
operation, 'array' for the first argument, 'BETSY_CROP' for the first image,
'array' for the second argument, 'BKGND' for the second image, and keep
'BETSY_CROP-BKGND' as the name for the difference. Display this difference
image with the MLx -> Show Image Array command.
Note that displaying this image takes longer than with the other images.
This is because it has real valued pixels, and real arithmetic is slower
in LISP than integer arithmetic. (Except where noted, MacLispix does not
use the floating point unit of the Macintosh, resulting in slower real arithmetic.
This has the temporary benefit of allowing MacLispix to run on Power PC's
in the emulated mode. MacLispix will run in native mode on the Power PC's
as the tools become available.)
The difference image took longer to display because it is a floating point
image, as can be seen with the command-i command, or the MLx -> Pixel Array
Ops -> Info command. 'Unsigned-byte 8' means that pixel values are integers
from 0-255, and 'double float' means they are 8 byte real numbers. Floating
point or 'real' arrays require much more computation time with the present
system, and requre eight times the memory (.4 MB vs .05 MB). Strictly speaking,
signed integer pixels would do for the subtraction operation. This is an
example of a general arithmetic operation, though, and most of the operators
result in real (floating point) values. The input arrays may have pixels
with any data type (except complex).
The MLx -> Show Values -> Limits -> Front Image command will show that the
range of values in the difference image is -63.0 -> 255.0. It is not unreasonable
that a difference image should have negative values. Although the difference
image has only integral values, the Real Arithmetic command automatically
places the results into a real valued array, so the values are printed as
real numbers.
The difference image may now be enhanced, either with scaling (on a pre-scaled
version using the MLx -> Scaling -> Prescale command since *BETSY_CROP-BKGND*
is a real valued array), or using the Contrast Slider.
To use the contrast slider, invoke the MLx -> Threshold Slider command.
Hold down the option key and double click on the slider twice. The bar will
turn gray. Slide both ends of the bar with the mouse until the limits, shown
at either end of the window, are around 80, and 120. This means that pixel
values (in the scaled difference image) of 80 and below are black, and values
of 120 and above are white. The values in between are given shades of gray
using a linear function. Compare the enhanced image to the un-enhanced difference
image by double clicking (no keys held down) on the slider to toggle the
slider off and on. Compare the enhanced difference with the original image
just by moving them side by side.
(Optional) To use a scaling routine, prescale the difference image
with the MLx -> Scaling -> Prescale command. Select the (real valued) difference
image. The full range of the image is given as the the default for the range
to scale. Click 'ok'. The default for the scaled range is given as 255 (one
byte worth). That degree of precision is sufficient for this case, so click
'ok'. Display the scaled image, then scale it with the MLx -> Scaling -> %
Outliers command, using 1 or .5 as the percentage to clip.
A line profile for the original, background and difference can be
made by invoking the MLx -> Show Values -> Line Profiles command as explained
previously. The line for the profile can be selected on any image except
the original, which is not the same size as the others. Select the arrays
desired by holding down the command (apple) key and clicking on them. The
image arrays are what are plotted, the images need not be displayed. All
that is necessary is to have one image displayed in order to set the position
of the line. The profiles for all the arrays are plotted, scaled from 0
(which clips negative values) to the maximum for the profile for that array.
