- Filtering Functions
- Plug-in Filters
- Binary
- Arithmatic
- Image Math
- FFT
- Subtract Background
- Apply LUT
- Enhance
- Equalize
- Fix Colors
**NIH Image Manual**

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.

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

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

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

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

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.

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.

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 -Repeatably 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.

Distance Map -Generates a Euclidian distance map (EDM). Each foreground (black) pixel in the binary image is replaced with a gray value equal to that pixel's distance from the nearest background (white) pixel. To reduce rounding errors, intermediate EDM values are stored as 16-bit values.

Ultimate Points -Generates the ultimate eroded points (UEPs) of the EDM. Requires a binary image as input. The UEPs represent the centers of particles that would be separated by segmentation. The UEP's gray value is equal to the radius of the inscribed circle of the corresponding particle. Note that the EDM is automatically smoothed when doing watershed segmentation but not when generating UEPs. You can force EDM smoothing, however, by holding down the option key while selecting the "Ultimate Points" command. Smoothing the EDM results in fewer noise induced errors but causes the gray values of the UEPs to be slightly lower, i.e. it slightly reduces the estimated particle sizes. Requires free ram equal to 2-5 times the image size.

Watershed -Separates touching convex particles. Requires free ram equal to 2-5 times the image size. Hold down the option key to disable EDM smoothing.

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.

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.

rsbweb.nih.gov/pub/nih-image/nih-image_spin-offs/imageFFT/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 rsbweb.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.

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.

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.