# Process Menu

> - Smooth
> - Sharpen
> - Find Edges
> - Enhance Contrast
> - Noise>
> - Shadows>
> - Binary>
> - Math>
> - FFT>
> - Filters>
> - Image Calculator...
> - Subtract Background...
> - Repeat Command

> ### Smooth

> Blurs the active image or selection. This filter replaces each pixel with the average of its 3x3 neighborhood.

> ### Sharpen

> Increases contrast and accentuates detail in the image or selection, but may also accentuate noise. This filter uses the following weighting factors to replace each pixel with a weighted average of the 3x3 neighborhood.

>         -1 -1 -1
>         -1 12 -1
>         -1 -1 -1

> ### Find Edges

> Uses a Sobel edge detector to highlight sharp changes in intensity in the active image or selection. Two 3x3 convolution kernels (show below) are used to generate vertical and horizontal derivatives. The final image is produced by combining the two derivatives using the square root of the sum of the squares.

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

> ### Enhance Contrast

> Enhances image contrast by using either histogram stretching or histogram equalization. Both methods are described in detail in the Hypermedia Image Processing Reference. Look up "enhancement" in the index. This command does not alter pixel values as long as Normalize or Equalize Histogram are not checked.

> The Saturated Pixels value determines the number of pixels in the image that are allowed to become saturated. Increasing this value will increase contrast. This value should be greater than zero to prevent a few outlying pixel from causing the histogram stretch to not work as intended.

> Check Normalize and ImageJ will recalculate the pixel values of the image so the range is equal to the maximum range for the data type, or 0-1.0 for float images. The maximum range is 0-255 for 8-bit images and 0-65535 for 16-bit images. Note that normalization of RGB images is not supported.

> Check Equalize Histogram to enhance the image using histogram equalization. Create a selection and the equalization will be based on the histogram of the selection. Uses a modified algorithm that takes the square root of the histogram values. Hold the alt key down to use the standard histogram equalization algorithm. The "Saturated Pixels" and "Normalize" parameters are ignored when Equalize Histogram is checked. The equalization code was contributed by Richard Kirk.

> ## Noise Submenu

> Use the commands in this submenu to add noise to images or remove it. For more advanced capabilities, check out Erik Meijering's RandomJ package (Binomial, Exponential, Gamma, Gaussian, Poisson and Uniform) at www.imagescience.org/meijering/software/randomj/.

> > ### Add Noise

> > Adds random noise to the image or selection. The noise is Gaussian (normally) distributed with a mean of zero and standard deviation of 25.

> > ### Add More Noise

> > Adds Gaussian noise with a mean of zero and standard deviation of 75.

> > ### Salt and Pepper

> > Adds salt and pepper noise to the image or selection by randomly replacing 2.5% of the pixels with black pixels and 2.5% with white pixels. Note: this command only works with 8-bit images.

> > ### Despeckle

> > This is a median filter. It replaces each pixel 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). Median filters a good at removing salt and pepper noise.

> > ### Remove Outliers

> > Replaces a pixel by the median of the pixels in the surrounding if it deviates from the median by more than a certain value (the threshold). Useful for correcting, e.g., hot pixels or dead pixels of a CCD image.

> > Radius determines the area used for calculating the median (uncalibrated, i.e., in pixels). See Process>Filters>Show Circular Masks to see how radius translates into an area. Threshold determinates by how much the pixel must deviate from the median to get replaced, in raw (uncalibrated) units. Which Outliers determines whether pixels brighter or darker than the surrounding (the median) should be replaced.

> ## Shadows Submenu

> Commands in this submenu produce a shadow effect, with light appearing to come from a direction corresponding to the command name. The commands use Convolve3x3, ImageJ's 3x3 convolution function. Two of the convolution kernels are shown in the illustration. Shadows Demo uses all eight kernels to demonstrate the speed of Convolve3x3.

> ## Binary Submenu

> This submenu contains commands that create or process binary (black and white) images. They assume that objects are black and background is white unless "Black Background" is checked in the Process>Binary>Options dialog box.

> > ### Make Binary

> > Converts an image to black and white. The threshold level is determined by analysing the histogram of the current selection, or of the entire image if there is no selection. The algorithm used to calculate the threshold is described in the FAQs. If a threshold has been set using the Image>Adjust>Threshold tool, a dialog pops up that lets you specify which pixels are set to the background color and which to the foreground color, and whether the background is black and the foreground is white.

> > With stacks, all images in the stack are converted to binary using the calculated threshold of the currently displayed slice. Use the ConvertStackToBinary macro to convert a stack to binary using locally calculated thresholds.

> > ### Convert to Mask

> > Converts the image to black and white based on the current threshold settings (if set) or on a threshold calculated by analyzing the histogram. The mask will have an inverting LUT (white is 0 and black is 255) unless "Black Background" is checked in the Process>Binary>Options dialog box.

> > ### Find Maxima... (v1.38 or later)

> > Determines the local maxima in an image and creates a binary (mask-like) image of the same size with the maxima, or one segmented particle per maximum, marked. For RGB images, maxima of luminance are selected, with the luminance defined as weighted or unweighted average of the colors depending on the Edit>Options>Conversions settings. This command is based on a plugin contributed by Michael Schmid.

> > A dialog box is displayed with the following options:

> > - "Noise Tolerance" - Maxima are ignored if they do not stand out from the surroundings by more than this value (calibrated units for calibrated images). In other words, a threshold is set at the maximum value minus noise tolerance and the contiguous area around the maximum above the threshold is analyzed. For accepting a maximum, this area must not contain any point with a value higher at than the maximum. Only one maximum within this area is accepted.
> > - "Output Type" can be:
> >   - "Single Points" - results in one single point per maximum
> >   - "Maxima Within Tolerance" - all points within the "Noise Tolerance" for each maximum
> >   - "Segmented Particles" - Assumes that each maximum belongs to a particle and segments the image by a watershed algorithm applied to the values of the image (in contrast to Process>Binary>Watershed, which uses the Euclidian distance map).
> >   - "Display Point selection" - Displays a multi-point selection with a point at each maximum
> >   - "Count" - Displays the number of maxima in the Results window
> > - "Exclude Edge Maxima" - Excludes maxima if the area within the noise tolerance surrounding a maximum touches the edge of the image (edge of the selection does not matter).
> > - "Above Lower Threshold" - (This option appears for thresholded images only.) Finds maxima above the lower threshold only. The upper threshold of the image is ignored. If "Segmented Particles" is selected as "Output Type", the area below the lower threshold is considered a background.

> > Output is a binary image, with foreground 255 and background 0, using an inverted or normal LUT depending on the "Black Background" option in Process>Binary>Options. The number of particles (as obtained by "Analyze Particles") in the output image does not depend on the "Output Type" selected. Note that "Segmented Particles" will usually result in particles touching the edge if "Exclude Edge Maxima" is selected. "Exclude Edge Maxima" applies to the maximum, not to the particle.

> > Find Maxima does not work on stacks, but the FindStackMaxima macro runs it on all the images in a stack and creates a second stack containing the output images.

> > ### Erode

> > Removes pixels from the edges of black objects. Use Process>Filters>Minimum to do grayscale erosion.

> > ### Dilate

> > Adds pixels to the edges of black objects. Use Process>Filters>Maximum to do grayscale dilation.

> > ### Open

> > Performs an erosion operation, followed by dilation. This smoothes objects and removes isolated pixels.

> > ### Close

> > Performs a dilation operation, followed by erosion. This smoothes objects and fills in small holes.

> > ### Options...

> > Display a dialog box that allows several settings used by commands in the Binary submenu to be altered.

> > Iterations specifies the number of times erosion, dilation, opening, and closing are performed. Count specifies the number of adjacent background pixels necessary before a pixel is removed from the edge of an object during erosion and the number of adjacent foreground pixels necessary before a pixel is added to the edge of an object during dilation. Check Black Background if the image has white objects on a black background.

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

> > ### Distance Map

> > Generates a Euclidian distance map (EDM). Each foreground pixel in the binary image is replaced with a gray value equal to that pixel's distance from the nearest background pixel.

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

> > ### Watershed

> > Watershed segmentation is a way of automatically separating or cutting apart particles that touch. It first calculates the Euclidian distance map (EDM) and finds the ultimate eroded points (UEPs). It then dilates each of the UEPs (the peaks or local maxima of the EDM) as far as possible - either until the edge of the particle is reached, or the edge of the region of another (growing) UEP. Watershed segmentation works best for smooth convex objects that don't overlap too much.

> > Enable debugging in Edit>Options>Misc and the Watershed command will create an animation that shows how the watershed algorithm works. An example is available.

> ## Math Submenu

> The commands in this submenu add (subtract, multiply, etc.) a constant to each pixel in the active image or selection. When the result value overflows/underflows the legal range of the image's data type, the value is reset to the maximum/minimum value. With stacks, selections are ignored and the specified operation is performed on all slices in the stack.

> > ### Add...

> > Adds a constant to the image. With 8-bit images, results greater than 255 are set to 255. With 16-bit signed images, results greater than 65,535 are set to 65,535.

> > ### Subtract...

> > Subtracts a constant from the image. With 8-bit and 16-bit images, results less than 0 are set to 0.

> > ### Multiply...

> > Multiplies the image by the specified real constant. With 8-bit images, results greater than 255 are set to 255. With 16-bit signed images, results greater than 65,535 are set to 65,535.

> > ### Divide...

> > Divides the image by the specified real constant. Attempts to divide by zero will be ignored.

> > ### AND...

> > Does a bitwise AND of the image and the specified binary constant.

> > ### OR...

> > Does a bitwise OR of the image and the specified binary constant.

> > ### XOR...

> > Does a bitwise XOR of the image and the specified binary constant.

> > ### Min...

> > Pixels in the image with a value less than the specified constant are replaced by the constant.

> > ### Max...

> > Pixels in the image with a value greater than the specified constant are replaced by the constant.

> > ### Gamma...

> > Applies the function f(p) = (p/255)^gamma*255 to each pixel (p) in the image or selection, where 0.1 <= gamma <= 5.0. For RGB images, this function is applied to all three color channels. For 16-bit images, the image min and max are used for scaling instead of 255.

> > ### Log...

> > For 8-bit images, applies the function f(p) = log(p) * 255/log(255) to each pixel (p) in the image or selection. For RGB images, this function is applied to all three color channels. For 16-bit images, the image min and max are used for scaling instead of 255. For float images, no scaling is done. To calculate log10 of the image, multiply the result of this operation by 0.4343 (1/log(10).

> > ### Reciprocal

> > Generates the reciprocal of the active image or selection. Only works with 32-bit float images.

> > ### NaN Background

> > Sets non-thresholded pixels in 32-bit float images to the NaN (Not a Number) value. For float images, the "Apply" option in Image>Adjust Threshold runs this command. Pixels with a value of Float.NaN (0f/0f), Float.POSITIVE_INFINITY (1f/0f) or Float.NEGATIVE_INFINITY (-1f/0f) are ignored when making measurements on 32-bit float images.

> > ### Abs

> > Generates the absolute value of the active image or selection. Only works with 32-bit float images.

> ## FFT Submenu

> The commands in this submenu support frequency domain display, editing and processing. They are based on an implementation of the 2D Fast Hartley Transform (FHT) contributed by Arlo Reeves, the author of the ImageFFT spinoff of NIH Image. For 3D FHTs, check out Bob Dougherty's 3D Fast Hartley Transform plugin.

> > ### FFT

> > Computes the Fourier transform and displays the power spectrum. The frequency domain image is stored as 32-bit float FHT attached to the 8-bit image that displays the power spectrum. Commands in this submenu, such as Inverse FFT, operate on the 32-bit FHT, not on the 8-bit power spectrum. All other ImageJ commands only "see" the power spectrum.

> > If the mouse is over an active frequency domain (FFT) window, its location is displayed in polar coordinates. The angle is expressed in degrees, while the radius is expressed in pixels per cycle (p/c). In ImageJ 1.33i or later, the radius is expressed in [units] per cycle (e.g. mm/c) if the spatial scale of the image was defined using Analyze>Set Scale. An example is available.

> > ### 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 ImageJ's selection tools and fill/clear commands to draw black or white areas that mask portions of the transformed image. Black areas (pixel value=0) cause the corresponding frequences to be filtered (removed) and white areas (pixel value=255) cause the corresponding frequences to be passed. It is not, however, possible to both filter and pass during the same inverse transform.

> > There is another example that demonstrates how to remove noise from images generated by a laser scanning confocal microscope.

> > ### Redisplay Power Spectrum

> > Recomputes the power spectrum from the frequency domain image (32-bit FHT). This command allows you to start over if you mess up while editing the 8-bit power spectrum image.

> > ### Bandpass Filter..

> > This is a built in version of Joachim Walter's FFT Filter plugin.

> > ### Custom Filter..

> > This command does fourier space filtering of the active using a user-supplied image as the filter. For examples, see the FFTCustomFilterDemo and FFTRemoveStreaks macros.

> > ### FD Math..

> > This command correlates, convolves or deconvolves two images. It does this by converting the images to the frequency domain, performing conjugate multiplication, multiplication or division, then converting the result back to the space domain. These three operations in the frequency domain are equivalent to correlation, convolution and deconvolution in the space domain. Refer to the DeconvolutionDemo and MotionBlurRemoval macros for an examples.

> ## Filters Submenu

> This submenu contains miscellaneous filters and plugin filters that have been installed by the Plugins>Utilities>Install Plugin command. For more information, refer to the Hypermedia Image Processing Reference at http://www.dai.ed.ac.uk/HIPR2/. Click on Index and look up the keywords convolution, Gaussian, median, mean, erode, dilate and unsharp.

> > ### Convolve...

> > Does spatial convolution using a kernel entered into a text area. A kernel is a matrix whose center corresponds to the source pixel and the other elements correspond to neighboring pixels. The destination pixel is calculated by multiplying each source pixel by its corresponding kernel coefficient and adding the results. There is no arbitrary limit to the size of the kernel but it must be square and have an odd width.

> > Rows in the text area must all have the same number of coefficients, the rows must be terminated with a carriage return, and the coefficients must be separated by one or more spaces. Kernels can be pasted into the text area using the control-V keyboard shortcut. Checking Normalize Kernel causes each coefficient to be divided by the sum of the coefficients, preserving image brightness.

> > The kernel shown is a 9 x 9 "Mexican hat", which does both smoothing and edge detection in one operation. Note that kernels can be saved in a text file (using copy (control-C) and paste), displayed as an image using File>Import>Text Image, scaled to a reasonable size using Image>Adjust>Size, and plotted using the Surface Plot plugin.

> > ### Gaussian Blur...

> > This filter uses convolution with a Gaussian function for smoothing. Sigma is the radius of decay to exp(-0.5) ~ 61%, i.e. the standard deviation sigma of the Gaussian (this is the same as in Photoshop, but different from earlier versions of ImageJ, where a value 2.5 times as much had to be entered.

> > Like all ImageJ convolution operations, it assumes that out-of-image pixels have a value equal to the nearest edge pixel. This gives higher weight to edge pixels than pixels inside the image, and higher weight to corner pixels than non-corner pixels at the edge. Thus, when smoothing with very high blur radius, the output will be dominated by the edge pixels and especially the corner pixels (in the extreme case, with a blur radius of e.g. 1e20, the image will be raplaced by the average of the four corner pixels).

> > For increased speed, except for small blur radii, the lines (rows or columns of the image) are downscaled before convolution and upscaled to their original length thereafter.

> > ### Median...

> > Reduces noise in the active image by replacing each pixel with the median of the neighboring pixel values.

> > ### Mean...

> > Smooths the current image by replacing each pixel with the neighborhood mean. The size of the neighborhood is specified by entering its radius in a dialog box.

> > ### Minimum...

> > This filter does grayscale erosion by replacing each pixel in the image with the smallest pixel value in that pixel's neighborhood.

> > ### Maximum...

> > This filter does grayscale dilation by replacing each pixel in the image with the largest pixel value in that pixel's neighborhood.

> > ### Unsharp Mask...

> > Unsharp masking subtracts a blurred copy of the image and rescales the image to obtain the same contrast of large (low-frequency) structures as in the input image. This is equivalent to adding a high-pass filtered image and thus sharpens the image. Radius is the standard deviation (blur radius) of the Gaussian blur that is subtracted. Mask Weight determines the strength of filtering, whereby Mask Weight=1 would be an infinite weight of the high-pass filtered image that is added.

> > ### Variance...

> > Heighlights edges in the image by replacing each pixel with the neighborhood variance.

> > ### Show Circular Masks

> > Generates a stack containing examples of the circular masks used by the Median, Mean, Minimum, Maximum and Variance filters for various neighborhood sizes.

> ### Image Calculator...

> Performs arithmetic and logical operations between two images selected from popup menus. Image1 or both Image1 and Image2 can be stacks. If both are stacks, they must have the same number of slices. Image1 and Image2 must be the same data type but they do not have to be the same size.

> You can select one of 12 operators from the Operation: popup menu. Check Create New Window and a new image or stack will be created to hold the result. Otherwise, the result of the operation replaces some or all of Image1. Check "32-bit Result" and the source images will be converted to 32-bit floating point before the specified operation is performed.

> With 32-bit (float) images, pixels resulting from division by zero are set to Infinity, or to NaN (Not a Number) if a zero pixel is divided by zero. The divide-by-zero value can be redefined in Edit>Options>Misc.

> Add | img1 = img1+img2
> Subtract | img1 = img1-img2
> Multiply | img1 = img1*img2
> Divide | img1 = img1/img2
> AND | img1= img1 AND img2
> OR | img1 = img1 OR img2
> XOR | img1 = img1 XOR img2
> Min | img1 = min(img1,img2)
> Max | img1 = max(img1,img2)
> Average | img1 = (img1+img2)/2
> Difference | img1 = |img1-img2|
> Copy | img1 = img2

> In these examples, the source and destination have inverted LUTs so zero pixels are white. Operations on images with non-inverted LUTs, and RGB images, will not produce the same results.

> ### Subtract Background...

> Removes smooth continuous backgrounds from gels and other images. Uses a rolling ball algorithm inspired by Stanley Sternberg's article, "Biomedical Image Processing", IEEE Computer, January 1983. Based on NIH Image Pascal code written by Michael Castle and Janice Keller of the University of Michigan Mental Health Research Institute. The Rolling Ball Radius should be at least as large as the radius of the largest object in the image that is not part of the background. For elongated objects, the radius should not be smaller than half the width of the smallest object.

> ### Repeat Command

> Reruns the previous command. The Undo and Open commands are skipped. For a shortcut, type shift-R.