- java.lang.Object
-
- ij.plugin.filter.MaximumFinder
-
- All Implemented Interfaces:
DialogListener
,ExtendedPlugInFilter
,PlugInFilter
public class MaximumFinder extends java.lang.Object implements ExtendedPlugInFilter, DialogListener
This ImageJ plug-in filter finds the maxima (or minima) of an image. It can create a mask where the local maxima of the current image are marked (255; unmarked pixels 0). The plug-in can also create watershed-segmented particles: Assume a landscape of inverted heights, i.e., maxima of the image are now water sinks. For each point in the image, the sink that the water goes to determines which particle it belongs to. When finding maxima (not minima), pixels with a level below the lower threshold can be left unprocessed. Except for segmentation, this plugin works with area ROIs, including non-rectangular ROIs, which define the area where maxima are reported. Since this plug-in creates a separate output image it processes only single images or slices, no stacks. Notes: - When using one instance of MaximumFinder for more than one image in parallel threads, all must images have the same width and height. version 09-Nov-2006 Michael Schmid version 21-Nov-2006 Wayne Rasband. Adds "Display Point Selection" option and "Count" output type. version 28-May-2007 Michael Schmid. Preview added, bugfix: minima of calibrated images, uses Arrays.sort version 07-Aug-2007 Fixed a bug that could delete particles when doing watershed segmentation of an EDM. version 21-Apr-2007 Adapted for float instead of 16-bit EDM; correct progress bar on multiple calls version 05-May-2009 Works for images>32768 pixels in width or height version 01-Nov-2009 Bugfix: extra lines in segmented output eliminated; watershed is also faster now Maximum points encoded in long array for sorting instead of separete objects that need gc New output type 'List' version 22-May-2011 Bugfix: Maximum search in EDM and float images with large dynamic range could omit maxima version 13-Sep-2013 added the findMaxima() and findMinima() functions for arrays (Norbert Vischer) version 20-Mar-2014 Watershed segmentation of EDM with tolerance>=1.0 does not kill fine particles version 11-Mar-2019 adds "strict" option, "noise tolerance" renamed to "prominence"
-
-
Field Summary
Fields Modifier and Type Field Description static int
COUNT
Do not create an image, just count maxima and add count to Results tablestatic int
IN_TOLERANCE
Output type all points around the maximum within the tolerancestatic int
LIST
Do not create an image, just list x, y of maxima in the Results tablestatic int
POINT_SELECTION
Do not create image, only mark pointsstatic int
SEGMENTED
Output type watershed-segmented imagestatic int
SINGLE_POINTS
Output type single points-
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 MaximumFinder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
dialogItemChanged(GenericDialog gd, java.awt.AWTEvent e)
Read the parameters (during preview or after showing the dialog)static int[]
findMaxima(double[] xx, double tolerance, boolean excludeOnEdges)
static int[]
findMaxima(double[] xx, double tolerance, int edgeMode)
Calculates peak positions of 1D array N.Vischer, 06-mar-2017ByteProcessor
findMaxima(ImageProcessor ip, double tolerance, boolean strict, double threshold, int outputType, boolean excludeOnEdges, boolean isEDM)
Here the processing is done: Find the maxima of an image (does not find minima).ByteProcessor
findMaxima(ImageProcessor ip, double tolerance, double threshold, int outputType, boolean excludeOnEdges, boolean isEDM)
Finds the maxima of an image (does not find minima).ByteProcessor
findMaxima(ImageProcessor ip, double tolerance, int outputType, boolean excludeOnEdges)
Find the maxima of an image.static int[]
findMinima(double[] xx, double tolerance, boolean excludeEdges)
Returns minimum positions of array xx, sorted with decreasing strengthstatic int[]
findMinima(double[] xx, double tolerance, int edgeMode)
java.awt.Polygon
getMaxima(ImageProcessor ip, double tolerance, boolean excludeOnEdges)
Finds the image maxima and returns them as a Polygon, where poly.npoints is the number of maxima.java.awt.Polygon
getMaxima(ImageProcessor ip, double tolerance, boolean strict, boolean excludeOnEdges)
Finds the image maxima and returns them as a Polygon, where poly.npoints is the number of maxima.void
run(ImageProcessor ip)
The plugin is inferred from ImageJ by this methodvoid
setNPasses(int nPasses)
Set his to the number of images to process (for the watershed progress bar only).int
setup(java.lang.String arg, ImagePlus imp)
Method to return types supportedint
showDialog(ImagePlus imp, java.lang.String command, PlugInFilterRunner pfr)
This method is called aftersetup(arg, imp)
unless theDONE
flag has been set.
-
-
-
Field Detail
-
SINGLE_POINTS
public static final int SINGLE_POINTS
Output type single points- See Also:
- Constant Field Values
-
IN_TOLERANCE
public static final int IN_TOLERANCE
Output type all points around the maximum within the tolerance- See Also:
- Constant Field Values
-
SEGMENTED
public static final int SEGMENTED
Output type watershed-segmented image- See Also:
- Constant Field Values
-
POINT_SELECTION
public static final int POINT_SELECTION
Do not create image, only mark points- See Also:
- Constant Field Values
-
LIST
public static final int LIST
Do not create an image, just list x, y of maxima in the Results table- See Also:
- Constant Field Values
-
COUNT
public static final int COUNT
Do not create an image, just count maxima and add count to Results table- See Also:
- Constant Field Values
-
-
Method Detail
-
setup
public int setup(java.lang.String arg, ImagePlus imp)
Method to return types supported- Specified by:
setup
in interfacePlugInFilter
- Parameters:
arg
- Not used by this plugin-filterimp
- The image to be filtered- Returns:
- Code describing supported formats etc. (see ij.plugin.filter.PlugInFilter & ExtendedPlugInFilter)
-
showDialog
public int showDialog(ImagePlus imp, java.lang.String command, PlugInFilterRunner pfr)
Description copied from interface:ExtendedPlugInFilter
This method is called aftersetup(arg, imp)
unless theDONE
flag has been set.- Specified by:
showDialog
in interfaceExtendedPlugInFilter
- Parameters:
imp
- The active image already passed in thesetup(arg, imp)
call. It will be null, however, if theNO_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 byaddPreviewCheckbox
to enable preview by calling therun(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 byrun(ip)
.- Returns:
- The method should return a combination (bitwise OR)
of the flags specified in interfaces
PlugInFilter
andExtendedPlugInFilter
.
-
dialogItemChanged
public boolean dialogItemChanged(GenericDialog gd, java.awt.AWTEvent e)
Read the parameters (during preview or after showing the dialog)- Specified by:
dialogItemChanged
in interfaceDialogListener
- Parameters:
gd
- A reference to the GenericDialog.e
- The event that has been generated by the user action in the dialog. Note thate
isnull
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).
-
setNPasses
public void setNPasses(int nPasses)
Set his to the number of images to process (for the watershed progress bar only). Don't call or set nPasses to zero if no progress bar is desired.- Specified by:
setNPasses
in interfaceExtendedPlugInFilter
-
run
public void run(ImageProcessor ip)
The plugin is inferred from ImageJ by this method- Specified by:
run
in interfacePlugInFilter
- Parameters:
ip
- The image where maxima (or minima) should be found
-
getMaxima
public java.awt.Polygon getMaxima(ImageProcessor ip, double tolerance, boolean excludeOnEdges)
Finds the image maxima and returns them as a Polygon, where poly.npoints is the number of maxima. There is an example at
http://imagej.nih.gov/ij/macros/js/FindMaxima.js.- Parameters:
ip
- The input imagetolerance
- Height tolerance: maxima are accepted only if protruding more than this value from the ridge to a higher maximumexcludeOnEdges
- Whether to exclude edge maxima. Also determines whether strict mode is on, i.e., whether the global maximum is accepted even if all other pixel are less than 'tolerance' below this level (In 1.52m and before, 'strict' and 'excludeOnEdges' were the same).- Returns:
- A Polygon containing the coordinates of the maxima, where poly.npoints is the number of maxima. Note that poly.xpoints.length may be greater than the number of maxima.
-
getMaxima
public java.awt.Polygon getMaxima(ImageProcessor ip, double tolerance, boolean strict, boolean excludeOnEdges)
Finds the image maxima and returns them as a Polygon, where poly.npoints is the number of maxima.- Parameters:
ip
- The input imagetolerance
- Height tolerance: maxima are accepted only if protruding more than this value from the ridge to a higher maximumstrict
- When off, the global maximum is accepted even if all other pixel are less than 'tolerance' below this level. WithexcludeOnEdges=true
, 'strict' also means that the surounding of a maximum within 'tolerance' must not include an edge pixel (otherwise, it is enough that there is no edge pixel with the maximum value).excludeOnEdges
- Whether to exclude edge maxima. Also determines whether strict mode is on, i.e., whether the global maximum is accepted even if all other pixel are less than 'tolerance' below this level (In 1.52m and before, 'strict' and 'excludeOnEdges' were the same).- Returns:
- A Polygon containing the coordinates of the maxima, where poly.npoints is the number of maxima. Note that poly.xpoints.length may be greater than the number of maxima.
-
findMaxima
public static int[] findMaxima(double[] xx, double tolerance, int edgeMode)
Calculates peak positions of 1D array N.Vischer, 06-mar-2017- Parameters:
xx
- Array containing peaks.tolerance
- Depth of a qualified valley must exceed tolerance. Tolerance must be >= 0. Flat tops are marked at their centers.edgeMode
- 0=include, 1=exclude, 3=circular edgeMode = 0 (include edges) peak may be separated by one qualified valley and by a border. edgeMode = 1 (exclude edges) peak must be separated by two qualified valleys edgeMode = 2 (circular) array is regarded to be circular- Returns:
- Positions of peaks, sorted with decreasing amplitude
-
findMaxima
public static int[] findMaxima(double[] xx, double tolerance, boolean excludeOnEdges)
-
findMinima
public static int[] findMinima(double[] xx, double tolerance, boolean excludeEdges)
Returns minimum positions of array xx, sorted with decreasing strength
-
findMinima
public static int[] findMinima(double[] xx, double tolerance, int edgeMode)
-
findMaxima
public ByteProcessor findMaxima(ImageProcessor ip, double tolerance, int outputType, boolean excludeOnEdges)
Find the maxima of an image.- Parameters:
ip
- The input imagetolerance
- Height tolerance: maxima are accepted only if protruding more than this value from the ridge to a higher maximumoutputType
- What to mark in output image: SINGLE_POINTS, IN_TOLERANCE or SEGMENTED. No output image is created for output types POINT_SELECTION, LIST and COUNT.excludeOnEdges
- Whether to exclude edge maxima. Also determines whether strict mode is on, i.e., whether the global maximum is accepted even if all other pixel are less than 'tolerance' below this level (In 1.52m and before, 'strict' and 'excludeOnEdges' were the same).- Returns:
- A new byteProcessor with a normal (uninverted) LUT where the marked points are set to 255 (Background 0). Pixels outside of the roi of the input ip are not set. Returns null if outputType does not require an output or if cancelled by escape
-
findMaxima
public ByteProcessor findMaxima(ImageProcessor ip, double tolerance, double threshold, int outputType, boolean excludeOnEdges, boolean isEDM)
Finds the maxima of an image (does not find minima). LIMITATIONS: With outputType=SEGMENTED (watershed segmentation), some segmentation lines may be improperly placed if local maxima are suppressed by the tolerance.- Parameters:
ip
- The input imagetolerance
- Height tolerance: maxima are accepted only if protruding more than this value from the ridge to a higher maximumthreshold
- minimum height of a maximum (uncalibrated); for no minimum height set it to ImageProcessor.NO_THRESHOLDoutputType
- What to mark in output image: SINGLE_POINTS, IN_TOLERANCE or SEGMENTED. No output image is created for output types POINT_SELECTION, LIST and COUNT.excludeOnEdges
- Whether to exclude edge maxima. Also determines whether strict mode is on, i.e., whether the global maximum is accepted even if all other pixel are less than 'tolerance' below this level (In 1.52m and before, 'strict' and 'excludeOnEdges' were the same).isEDM
- Whether the image is a float Euclidian Distance Map.- Returns:
- A new byteProcessor with a normal (uninverted) LUT where the marked points are set to 255 (Background 0). Pixels outside of the roi of the input ip are not set. Returns null if outputType does not require an output or if cancelled by escape
-
findMaxima
public ByteProcessor findMaxima(ImageProcessor ip, double tolerance, boolean strict, double threshold, int outputType, boolean excludeOnEdges, boolean isEDM)
Here the processing is done: Find the maxima of an image (does not find minima). LIMITATIONS: With outputType=SEGMENTED (watershed segmentation), some segmentation lines may be improperly placed if local maxima are suppressed by the tolerance.- Parameters:
ip
- The input imagetolerance
- Height tolerance: maxima are accepted only if protruding more than this value from the ridge to a higher maximumstrict
- When off, the global maximum is accepted even if all other pixel are less than 'tolerance' below this level. WithexcludeOnEdges=true
, 'strict' also means that the surounding of a maximum within 'tolerance' must not include an edge pixel (otherwise, it is enough that there is no edge pixel with the maximum value).threshold
- Minimum height of a maximum (uncalibrated); for no minimum height set it to ImageProcessor.NO_THRESHOLDoutputType
- What to mark in output image: SINGLE_POINTS, IN_TOLERANCE or SEGMENTED. No output image is created for output types POINT_SELECTION, LIST and COUNT.excludeOnEdges
- Whether to exclude edge maximaisEDM
- Whether the image is a float Euclidian Distance Map.- Returns:
- A new byteProcessor with a normal (uninverted) LUT where the marked points are set to 255 (Background 0). Pixels outside of the roi of the input ip are not set. Returns null if outputType does not require an output or if cancelled by escape
-
-