### Filtering Functions (Smooth, Sharpen, etc.)

These filters, with the exception of Reduce Noise and Dither, are implemented using 3 x 3 spatial convolutions, where the value of each pixel in the selection is replaced with the weighted average of its 3 x 3 neighborhood. They are not limited to rectangular selections. The entire image is filtered if no selection is active. They do not work correctly with 8-bit true color images. They can be aborted by typing command-period.

The 3 x 3 tables shown below are the coefficients (weighting factors) for the filters. The popularity of plus and minus one in these tables is due to the fact that multiplication by one is very efficient, i.e., it is unnecessary.

Smooth - Blurs (softens) the selected area. It can be used to reduce noise in an image. Hold the option key down for increased blurring.

```    1 1 1    1 1 1 (If option key down)
1 4 1    1 1 1
1 1 1    1 1 1
```

Sharpen - Increases contrast and accentuates detail in the selection, but may also accentuate noise. To minimize this problem, you can Smooth and/or Reduce Noise before using Sharpen. Hold the option key down for increased sharpening.

```    -1 -1 -1    -1 -1 -1   (If option key down)
-1 12 -1    -1  9 -1
-1 -1 -1    -1 -1 -1
```

Shadow - Produces a shadow effect, with the light appearing to come from a direction specified in a dialog box. Three of the kernels used are shown below.

```      West     North West     North
1  0 -1     2  1  0      1  2  1
2  1 -2     1  1 -1      0  1  0
1  0 -1     0 -1 -2     -1 -2 -1
```

Find Edges - Performs a Sobel edge detection operation. Two convolutions are done using the kernels shown below, generating vertical and horizontal derivatives. The results are then combined by using the square root of the sum of the squares of the two derivatives.

```    1   2   1     1   0  -1
0   0   0     2   0  -2
-1  -2  -1     1   0  -1
```

### Rank Filters

These filters rank (sort) the nine pixels in each 3 x 3 neighborhood and replace the center pixel with the median, minimum (lightest), or maximum (darkest) value. Use the Median filter to reduces noise. The Minimum filter erodes (shrinks) objects in grayscale images similar to the way binary erosion shrinks objects in binary images. The Maximum filter dilates (expands) objects in grayscale images similar to the way binary dilation expands objects in binary images.

Select Median and each pixel will be replaced with the median value in its 3 x 3 neighborhood. This is a time consuming operation because, for each pixel in the selection, the nine pixels in the 3x3 neighborhood must be sorted and the center pixel replaced with the median value (the fifth). To demonstrate the effectiveness of median filtering, try removing random spot noise generated using the spray can tool with the diameter set to 50 or greater.

Select Minimum and each pixel is replaced with the minimum value in the 3 x 3 neighborhood. With binary images, this produces the same result as the Binary/Erode filter with count set to one.

Select Maximum and each pixel is replaced with the maximum value in the 3 x 3 neighborhood. With binary images, this produces the same result as the Binary/Dilate filter with count set to one.

Select Opening and Iterations erosion operations are performed, followed by Iterations dilations. Select Closing and Iterations dilation operations are performed, followed by Iterations erosions.

### Dither

Uses the Floyd-Steinberg error diffusion algorithm to convert the current selection to a binary (black and white only) image. Dithering can be useful for exporting pictures to applications such as MacPaint or MacDraw that can only accept binary images. Dithering can also be used for printing on the ImageWriter, or other non-PostScript printers. The quality of dithered images can frequently be improved by increasing contrast using the controls in the Map window before doing the dithering. True color images should be converted to grayscale by using the Convert to Grayscale variation of the Apply LUT command before being dithered.

### Convolve

Does spatial convolutions using kernels read from a text file or text window. Kernels can be up to 63 x 63 in size. Output pixel values are clipped to 8-bits unless Scale Convolutions is checked in the Preferences dialog box. Use Image 's built-in text editor to create or examine these kernels.

As an example, use the New command to open a blank text window, enter (or paste) the following kernel, then use the Convolve command to try it out.

```     0  0  0 -1 -1 -1  0  0  0
0 -1 -1 -3 -3 -3 -1 -1  0
0 -1 -3 -3 -1 -3 -3 -1  0
-1 -3 -3  6 13  6 -3 -3 -1
-1 -3 -1 13 24 13 -1 -3 -1
-1 -3 -3  6 13  6 -3 -3 -1
0 -1 -3 -3 -1 -3 -3 -1  0
0 -1 -1 -3 -3 -3 -1 -1  0
0  0  0 -1 -1 -1  0  0  0
```

This is a 9 x 9 "Mexican hat" filter which will do both smoothing and edge detection in one operation. Each line should be terminated with a carriage return, and the coefficients should be separated by one or more spaces, or a tab. Note that kernels, such as this one, can be opened and displayed as an image using the Import (Text) command, scaled to a reasonable size using Scale and Rotate, and plotted using the Surface Plot command.

### Plug-in Filters

Use this sub-menu to run Photoshop compatible filter plug-ins. The plug-ins must be stored in a folder named "Plug-ins" located either in the same folder as Image or in the System Folder.

### Binary

The commands in this sub-menu are used to convert grayscale images to binary (i.e. black and white only), and to process these binary images. Note that Erode and Dilate do not perform erosion and dilation with structuring elements as described in the literature of classical mathematical morphological. However, several of the Mac image processing programs listed in Appendix D, such as "Alice", do support mathematical morphology.

Make Binary - Converts the current grayscale image to binary by setting pixels that have been highlighted by either density slicing or by thresholding to black (255), and all other pixels to white (0).

Erode - Removes pixels from the edges of objects in a binary images, where contiguous black areas in the image are considered objects, and background is assumed to be white. A pixel is removed (set to white) if four or more of its eight neighbors are white. Erosion separates objects that are touching and removes isolated pixels.

Dilate - Adds pixels to the edges of objects in a binary images. A pixel is added (set to black) if four or more of its eight neighbors are black. Dilation connects discontinuous objects and fills in holes.

Open - Performs an erosion operation, followed by dilation, which smoothes objects and remove isolated pixels.

Close - Performs a dilation operation, followed by erosion, which smoothes objects and fill in small holes.

Set Count - Allows you to specify the number of adjacent background or foreground pixels necessary before a pixel is removed from or added to the edge of objects during erosion or dilation operations. The default is four.

Set Iterations - Allows you to specify the number of times erosion, dilation, opening, and closing are performed. The default is one.

Outline - Generates a one pixel wide outline of objects in a binary image.

Skeletonize - Repeatable removes pixels from the edges of objects in a binary image until they are reduced to single pixel wide skeletons. Type command-period to abort.

### Arithmetic

The commands in this sub-menu add (subtract, multiply, etc.) a constant to each pixel in the current rectangular selection, or if there is no selection, the entire image.

If Real Result is checked in the dialog box, calibrated pixel values are used and the result is stored, in a new window, as both 32-bit real and scaled 8-bit images. The 8-bit image is calibrated using a linear calibration function so that commands in Image that only "see" the 8-bit image (currently everything accept Arithmetic, Image Math and FFT) will use approximations of the real pixel values.

Add - Adds a constant to each pixel in the selection. Results greater than 255 are set to 255.

Subtract - Subtracts a constant from each pixel in the selection. Results less than 0 are set to 0.

Multiply - Multiplies each pixel in the selection by a constant. Results greater than 255 are set to 255.

Divide - Divides each pixel in the selection by a constant.

Log - Replaces each pixel (V) in the selection with ln(V) * 255.0 / ln(255.0), where ln(V) is the natural logarithm(loge) of V. The result is set to 0 if V is equal to 0.

AND, OR, XOR - Performs the selected Boolean operation on each pixel in the selection.

### Image Math

Performs arithmetic and logical operations between two images selected from pop-up menus. The operation to be performed is also selected from a pop-up menu.

For each pixel, the arithmetic operation is performed, the result is multiplied by the scale factor, the offset value is added, and the final result is clipped to 8-bits (0-255). The operations are carried out in the upper left corner of each image using the largest common rectangle.

If Real Result is checked, the calibrated pixel values for the two input images are used and the result is stored, in the same window, as both 32-bit real and scaled 8-bit images. The 8-bit image is calibrated using a linear calibration function so that commands in Image that only "see" the 8-bit image (currently everything accept Arithmetic, Image Math and FFT) will use approximations of the real pixel values. Notice that the name in the result window's title bar is enclosed in angle brackets to indicate that the it contains a real image. Also note the white diamond, indicating that the scaled 8-bit result is density calibrated.

### FFT

The commands in this submenu support frequency domain display, editing and processing. They use a real, 2D Fast Hartley Transform (FHT) routine contributed by Arlo Reeves, the author of ImageFFT. For more information about the FHT and ImageFFT, see the ImageFFT documentation, example images, and Arlo's thesis, available from the nih-image_spinoffs directory on zippy.nimh.nih.gov.

Note that FFTs and inverse FFTs require extensive floating-point calculations and are therefore very slow on 68000 Macs.

FFT - Computes the Fourier transform and displays the power spectrum. Requires a square, power of two size image or selection. The transformed frequency domain image is stored in a 32-bit real buffer attached to the window displaying the power spectrum. The only commands in Image that currently recognize this real image are "Inverse FFT", "Redisplay Power Spectrum" and "Image Math". All other commands "see" only the 8-bit power spectrum.

A helpful trick to remember when attempting to make power of two sized selections is to hold down the shift key, which forces the selection to be square. Or, even easier, use the macros for creating power of two sized selections in the "FFT Macros" file distributed with Image . The "FFT Macros" file also contains macros for high and low pass filtering.

Inverse FFT - Computes the inverse Fourier transform. You can filter or mask spots on the transformed (frequency domain) image and do an inverse transform to produce an image which only contains the frequencies selected or which suppresses the frequencies selected. Use Image 's editing and selections tools to draw black or white areas that mask portions of the transformed image. Black areas (pixel value=255) will pass the corresponding frequencies and white areas (pixel value=0) will filter out the corresponding frequencies. It is not, however, possible to both pass and filter during the same inverse transform. The "fft_example.bin" test image in the images directory on zippy.nimh.nih.gov provides an example of FFT editing and filtering.

Redisplay Power Spectrum - Recomputes the power spectrum from the real frequency domain image. This command allows you to start over if you mess up while editing the power spectrum display.

Swap Quadrants - Swaps quadrants 1 and 3 and quadrants 2 and 4 of the active image. Requires an 8-bit image whose height and width are equal and a power of two. Quadrant swapping is performed automatically every time a power spectrum is computed. In the normal, un-swapped, state, the power spectrum's central peak is distributed among the four corners of the image. While this is the format used in all computations, it doesn't correspond to nature's FFT analog, the diffraction pattern. This command is useful because cross and auto-correlation operations (the "cMul" operator in Image Math) result in inherently un-swapped space domain images, yet like power spectra, correlation functions are often displayed in quadrant swapped format. The Swap Quadrants command lets you choose the format you desire.

The transformed frequency domain images created by the FFT command are stored as 32-bit real images. The name in the window's title bar is enclosed in angle brackets (e.g., "<<FFT 2>>") to indicate that the window includes a real image. Note that frequency domain images require 5 times as much memory as normal 8-bit images - 4 bytes/pixel for the real image and 1 byte/pixel for the power spectrum image. The only commands in Image that currently recognize real images are "Arithmetic", "FFT", "Inverse FFT", "Redisplay Power Spectrum" and "Image Math". All other commands "see" only the 8-bit power spectrum.

The Image Math command supports arithmetic operations on the real images created by the FFT command. You can use it for multiplication (convolution), division (deconvolution) and conjugate multiplication (crosscorrelation and autocorrelation) of frequency domain images. There are macros in the "FFT Macros" file for doing autocorrelation. See the ImageFFT documentation and "The Image Processing Handbook" by John Russ for examples of how these operations can be used to analyze images.

### Subtract Background

The commands in this sub-menu remove smooth continuous backgrounds from gels and other images. The rolling ball and rolling disk algorithms used by these routines were inspired by Stanley Sternberg's article, "Biomedical Image Processing", IEEE Computer, January 1983. The routines were written by Michael Castle and Janice Keller of the University of Michigan Mental Health Research Institute.
1D Horizontal - Rolls an arc (rolling arc) horizontally under each row (shrunk 2 or 4 times) of the image in order to remove the background.

1D Vertical - Rolls an arc (rolling arc) vertically under each column (shrunk 2 or 4 times) of the image in order to remove the background.

2D Rolling Ball - Rolls a patch from the top of a sphere (rolling ball) under every point in the image (shrunk 4 or 8 times) in order to find the background.

2D Remove Streaks - Gets rid of horizontal and vertical streaks as it removes background by calling 1D Horizontal and 1D Vertical consecutively.

Faster - When checked, the image is shrunk 8 times (instead of 4) for 2D rolling ball subtraction. When the ball radius is less than 15 the image is shrunk 4 times (instead of 2).

Set Radius - Allows you to set the rolling ball or disk radius. Generally, the disk/ball radius should be at least as large as the diameter of the largest object in the image that is not part of the background.

### Apply LUT

Applies the current look-up table function to each pixel in the current selection (or the entire image if there is no current selection) and restores the default look-up table (the identity function). This modifies the gray values so that when the image is viewed using the default grayscale look-up table it will look the same as it did before. It also makes any brightness and contrast changes permanent. It can be used to posterize (reduce the number of gray values) an image by loading and applying, for example, a LUT consisting of four shades of gray. It can also be used to convert color images to grayscale, and to convert a thresholded image to binary.

If density slicing is in effect, the above dialog box is displayed, allowing you to process highlighted pixels in one way, and all other pixels another way.

### Enhance Contrast

Enhances the contrast of the currently active image. A new look-up table function is generated by doing a linear histogram stretch of the current selection. Use the Apply LUT command to make the contrast change permanent. Enhance Contrast does not work with true color images.

### Equalize

Performs histogram equalization based on the density histogram of the current selection. A new look-up table function is generated that more evenly distributes the gray values of the image. The newly created function is displayed in the Map window. Use Apply LUT to make the contrast change permanent. Equalization does not work with true color images.

### Fix Colors

Attempts to correct color anomalies by mapping pixels with values of either 0 or 255 to the nearest matching color in the other 254 LUT entries. This usually corrects pseudo-color problems due to the way Image "hard wires" entries 0 and 255 to white and black respectively.

[Next] [Contents] [Home]