# Filter Examples

Image courtesy of Dr. Chris Obara

### Gaussian Smoothing

Gaussian smoothing can remove noise from an image. Above is an extreme example of smoothing out all small objects. In HIP the size of objects to be smoothed are defined by the sigma parameter. This defines the width of one standard deviation in the Gaussian curve to be applied to the neighborhood of each pixel.

â€‹

MATLAB code:

diameter = 1./pixelPhysicalSize; % in the example the pixel size is

% [0.0397, 0.0397, 0.1096] um (x,y,z)

numberOfIterations = 1;

imGaussSmoothed = HIP.Gaussian(im2, diameter./4, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Mean Smoothing

Mean smoothing can remove noise from an image by blurring the intensities in a neighborhood. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([5,5,3]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMean = HIP.MeanFilter( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Median Smoothing

Median smoothing can remove noise from an image by blurring the intensities in a neighborhood. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter will preserve edges better than the mean filter and is less affected by extreme values.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([5,5,3]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMean = HIP.MedianFilter( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Wiener Smoothing

Wiener smoothing can remove noise from an image by blurring the intensities in a neighborhood. This filter, unlike the mean and median filters, takes into consideration a noise estimate. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter will preserve edges better than the mean and median filters.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([3,3,1]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMean = HIP.WienerFilter(im , neighborhood ,[ ], [ ]);

% The first empty array can be filled with a noise estimate.

% Leaving it blank uses the variance of the image

% leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Highpass Filter

A high pass filter removes low frequency background. This unwanted signal is typically from out of focus light. The underlying process involves estimating the background with a Gaussian smoothing and then subtracting that image from the original, leaving only the high frequency or sharp contrast areas.

â€‹

MATLAB code:

diameter = 1./pixelPhysicalSize; % in the example the pixel size is

% [0.0397, 0.0397, 0.1096] um (x,y,z)

imHP = HIP.HighPassFilter( im, diameter./2, [ ]);

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Erosion Filter

The erosion filter shrinks objects by replacing values with the minimum value within a neighborhood. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter can be applied iteratively with a simple parameter.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([3,3,1]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMin = HIP.MinFilter( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Dilation Filter

The dilation filter grows objects by replacing values with the maximum value within a neighborhood. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter can be applied iteratively with a simple parameter.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([3,3,1]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMax = HIP.MaxFilter( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Opening Filter

The opening filter accentuates holes and gaps. This filter will also remove smaller objects. This filter is essentially an erosion followed by a dilation.

The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter can be used iteratively with a simple parameter. Iteratively in this filter means that the erosion will be performed as many times as specified followed by the same number of dilations.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([3,3,1]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imOpen = HIP.Opener( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Closing Filter

The closing filter shrinks or closes holes and gaps. This filter is essentially a dilation followed by an erosion.

The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter can be used iteratively with a simple parameter. Iteratively in this filter means that the dilation will be performed as many times as specified followed by the same number of erosions.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([7,7,3]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imClose = HIP.Closure(im, neighborhood, numIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### LoG Filter

Median smoothing can remove noise from an image by blurring the intensities in a neighborhood. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter will preserve edges better than the mean filter will and is less affected by extreme values.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([3,3,1]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMean = HIP.MedianFilter( im, neighborhood, numberOfIterations, [ ] );

% leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

## Example coming soon

### Entropy Filter

Median smoothing can remove noise from an image by blurring the intensities in a neighborhood. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

This filter will preserve edges better than the mean filter will and is less affected by extreme values.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([3,3,1]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imMean = HIP.MedianFilter( im, neighborhood, numberOfIterations, [ ] );

% leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

## Example coming soon

### Standard Deviation Filter

The standard deviation filter will indicate how much change is in the neighborhood adjacent pixels. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([5,5,3]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imStd = HIP.StdFilter( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.

### Variance Filter

The variance filter will indicate how much change is in the neighborhood adjacent pixels. The amount and shape of the smoothing effect is dependent on the definition of the neighborhood. HIP provides an easy way to create an ellipsoidal neighborhood. However, any neighborhood can be defined by a binary mask where positions with ones (1) will be considered and zeros (0) will not.

â€‹

MATLAB code:

neighborhood = HIP.MakeEllipsoidMask([5,5,3]);

% These are the radii of the ellipsoid in (X,Y,Z).

numberOfIterations = 1;

imVar = HIP.VarFilter( im, neighborhood, numberOfIterations, [ ] );

% Leaving the last parameter as an empty array allows HIP to

% use all available GPUs.