Module ij
Package ij.plugin.filter

# Class RankFilters

java.lang.Object
ij.plugin.filter.RankFilters

All Implemented Interfaces:
  `DialogListener`, `ExtendedPlugInFilter`, `PlugInFilter`

public class RankFilters extends Object implements ExtendedPlugInFilter, DialogListener
This plugin implements the Mean, Minimum, Maximum, Variance, Median, Remove Outliers, Remove NaNs and Despeckle commands.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`BRIGHT_OUTLIERS`
`static final int`
`CLOSE`
`static final int`
`DARK_OUTLIERS`
`static final int`
`DESPECKLE`
`static final int`
`MAX`
`static final int`
`MEAN`
`static final int`
`MEDIAN`
`static final int`
`MIN`
`static final int`
`OPEN`
`static final int`
`OUTLIERS`
`static final int`
`REMOVE_NAN`
`static final int`
`TOP_HAT`
`static final int`
`VARIANCE`

### Fields inherited from interface ij.plugin.filter.ExtendedPlugInFilter

`KEEP_PREVIEW`

### Fields inherited from interface ij.plugin.filter.PlugInFilter

`CONVERT_TO_FLOAT, DOES_16, DOES_32, DOES_8C, DOES_8G, DOES_ALL, DOES_RGB, DOES_STACKS, DONE, FINAL_PROCESSING, KEEP_THRESHOLD, NO_CHANGES, NO_IMAGE_REQUIRED, NO_UNDO, NO_UNDO_RESET, PARALLELIZE_IMAGES, PARALLELIZE_STACKS, ROI_REQUIRED, SNAPSHOT, STACK_REQUIRED, SUPPORTS_MASKING`

## Constructor Summary

Constructors
Constructor
Description
`RankFilters()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`dialogItemChanged(GenericDialog gd, AWTEvent e)`
This method is invoked by a Generic Dialog if any of the inputs have changed (CANCEL does not trigger it; OK and running the dialog from a macro only trigger the first DialogListener added to a GenericDialog).
`static final float`
`findNthLowestNumber(float[] buf, int bufLength, int n)`
Find the n-th lowest number in part of an array
`void`
`makeKernel(double radius)`
Deprecated.
Not needed any more, use the rank(ip, ...) method, which creates the kernel
`protected int[]`
`makeLineRadii(double radius)`
Create a circular kernel (structuring element) of a given radius.
`void`
`rank(ImageProcessor ip, double radius, int filterType)`
Filters an image by any method except 'despecle', 'remove outliers', or top-hat
`void`
`rank(ImageProcessor ip, double radius, int filterType, int whichOutliers, float threshold)`
Filters an image by any method except 'despecle' and top-hat (for 'despeckle', use 'median' and radius=1)
`void`
`rank(ImageProcessor ip, double radius, int filterType, int whichOutliers, float threshold, boolean lightBackground, boolean dontSubtract)`
Filters an image by any method except 'despecle' (for 'despeckle', use 'median' and radius=1)
`void`
`run(ImageProcessor ip)`
Filters use this method to process the image.
`void`
`setNPasses(int nPasses)`
This method is called by ImageJ to set the number of calls to run(ip) corresponding to 100% of the progress bar.
`int`
`setup(String arg, ImagePlus imp)`
Setup of the PlugInFilter.
`int`
`showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)`
This method is called after `setup(arg, imp)` unless the `DONE` flag has been set.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### MEAN

public static final int MEAN

See Also:
  - Constant Field Values

### MIN

public static final int MIN

See Also:
  - Constant Field Values

### MAX

public static final int MAX

See Also:
  - Constant Field Values

### VARIANCE

public static final int VARIANCE

See Also:
  - Constant Field Values

### MEDIAN

public static final int MEDIAN

See Also:
  - Constant Field Values

### OUTLIERS

public static final int OUTLIERS

See Also:
  - Constant Field Values

### DESPECKLE

public static final int DESPECKLE

See Also:
  - Constant Field Values

### REMOVE_NAN

public static final int REMOVE_NAN

See Also:
  - Constant Field Values

### OPEN

public static final int OPEN

See Also:
  - Constant Field Values

### CLOSE

public static final int CLOSE

See Also:
  - Constant Field Values

### TOP_HAT

public static final int TOP_HAT

See Also:
  - Constant Field Values

### BRIGHT_OUTLIERS

public static final int BRIGHT_OUTLIERS

See Also:
  - Constant Field Values

### DARK_OUTLIERS

public static final int DARK_OUTLIERS

See Also:
  - Constant Field Values

## Constructor Details

### RankFilters

public RankFilters()

## Method Details

### setup

public int setup(String arg, ImagePlus imp)
Setup of the PlugInFilter. Returns the flags specifying the capabilities and needs of the filter.

Specified by:
  `setup` in interface `PlugInFilter`
Parameters:
  `arg` - Defines type of filter operation
  `imp` - The ImagePlus to be processed
Returns:
  Flags specifying further action of the PlugInFilterRunner

### showDialog

public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
Description copied from interface: `ExtendedPlugInFilter`
This method is called after `setup(arg, imp)` unless the `DONE` flag has been set.

Specified by:
  `showDialog` in interface `ExtendedPlugInFilter`
Parameters:
  `imp` - The active image already passed in the `setup(arg, imp)` call. It will be null, however, if the `NO_IMAGE_REQUIRED` flag has been set.
  `command` - The command that has led to the invocation of the plugin-filter. Useful as a title for the dialog.
  `pfr` - The PlugInFilterRunner calling this plugin-filter. It can be passed to a GenericDialog by `addPreviewCheckbox` to enable preview by calling the `run(ip)` method of this plugin-filter. `pfr` can be also used later for calling back the PlugInFilterRunner, e.g., to obtain the slice number currently processed by `run(ip)`.
Returns:
  The method should return a combination (bitwise OR) of the flags specified in interfaces `PlugInFilter` and `ExtendedPlugInFilter`.

### dialogItemChanged

public boolean dialogItemChanged(GenericDialog gd, AWTEvent e)
Description copied from interface: `DialogListener`
This method is invoked by a Generic Dialog if any of the inputs have changed (CANCEL does not trigger it; OK and running the dialog from a macro only trigger the first DialogListener added to a GenericDialog).

Specified by:
  `dialogItemChanged` in interface `DialogListener`
Parameters:
  `gd` - A reference to the GenericDialog.
  `e` - The event that has been generated by the user action in the dialog. Note that `e` is `null` if the dialogItemChanged method is called after the user has pressed the OK button or if the GenericDialog has read its parameters from a macro.
Returns:
  Should be true if the dialog input is valid. False disables the OK button and preview (if any).

### run

public void run(ImageProcessor ip)
Description copied from interface: `PlugInFilter`
Filters use this method to process the image. If the `PlugInFilter.DOES_STACKS` flag was set, it is called for each slice in a stack. With `PlugInFilter.CONVERT_TO_FLOAT`, the filter is called with the image data converted to a FloatProcessor (3 times per image for RGB images). ImageJ will lock the image before calling this method and unlock it when the filter is finished. For PlugInFilters specifying the `PlugInFilter.NO_IMAGE_REQUIRED` flag and not the `PlugInFilter.DONE` flag, run(ip) is called once with the argument `null`. Use ip.getSliceNumber() to get the stack position (1-n).

Specified by:
  `run` in interface `PlugInFilter`

### rank

public void rank(ImageProcessor ip, double radius, int filterType)
Filters an image by any method except 'despecle', 'remove outliers', or top-hat

Parameters:
  `ip` - The ImageProcessor that should be filtered (all 4 types supported)
  `radius` - Determines the kernel size, see Process>Filters>Show Circular Masks. Must not be negative. No checking is done for large values that would lead to excessive computing times.
  `filterType` - May be MEAN, MIN, MAX, VARIANCE, or MEDIAN.

### rank

public void rank(ImageProcessor ip, double radius, int filterType, int whichOutliers, float threshold)
Filters an image by any method except 'despecle' and top-hat (for 'despeckle', use 'median' and radius=1)

Parameters:
  `ip` - The image subject to filtering
  `radius` - The kernel radius
  `filterType` - as defined above; DESPECKLE is not a valid type here; use median and a radius of 1.0 instead
  `whichOutliers` - BRIGHT_OUTLIERS or DARK_OUTLIERS for 'outliers' filter
  `threshold` - Threshold for 'outliers' filter

### rank

public void rank(ImageProcessor ip, double radius, int filterType, int whichOutliers, float threshold, boolean lightBackground, boolean dontSubtract)
Filters an image by any method except 'despecle' (for 'despeckle', use 'median' and radius=1)

Parameters:
  `ip` - The image subject to filtering
  `radius` - The kernel radius
  `filterType` - as defined above; DESPECKLE is not a valid type here; use median and a radius of 1.0 instead
  `whichOutliers` - BRIGHT_OUTLIERS or DARK_OUTLIERS for 'outliers' filter
  `threshold` - Threshold for 'outliers' filter
  `lightBackground` - for top-hat background subtraction, background is light, not dark
  `dontSubtract` - fpr top-hat filter, performs a grayscale open or close instead of top-hat, where the result of grayscale open/close is subtracted from the original.

### findNthLowestNumber

public static final float findNthLowestNumber(float[] buf, int bufLength, int n)
Find the n-th lowest number in part of an array

Parameters:
  `buf` - The input array. Only values 0 ... bufLength are read. `buf` will be modified.
  `bufLength` - Number of values in `buf` that should be read
  `n` - which value should be found; n=0 for the lowest, n=bufLength-1 for the highest
Returns:
  the value

### makeKernel

public void makeKernel(double radius)
Deprecated.
Not needed any more, use the rank(ip, ...) method, which creates the kernel

### makeLineRadii

protected int[] makeLineRadii(double radius)
Create a circular kernel (structuring element) of a given radius.

Parameters:
  `radius` - Radius = 0.5 includes the 4 neighbors of the pixel in the center, radius = 1 corresponds to a 3x3 kernel size.
Returns:
  the circular kernel The output is an array that gives the length of each line of the structuring element (kernel) to the left (negative) and to the right (positive): [0] left in line 0, [1] right in line 0, [2] left in line 2, ... The maximum (absolute) value should be kernelRadius. Array elements at the end: length-2: nPoints, number of pixels in the kernel area length-1: kernelRadius in x direction (kernel width is 2*kernelRadius+1) Kernel height can be calculated as (array length - 1)/2 (odd number); Kernel radius in y direction is kernel height/2 (truncating integer division). Note that kernel width and height are the same for the circular kernels used here, but treated separately for the case of future extensions with non-circular kernels.

### setNPasses

public void setNPasses(int nPasses)
This method is called by ImageJ to set the number of calls to run(ip) corresponding to 100% of the progress bar. Setting nPasses=0 suppresses the progress bar

Specified by:
  `setNPasses` in interface `ExtendedPlugInFilter`