ij.plugin.filter
Class MaximumFinder

java.lang.Object
  extended by ij.plugin.filter.MaximumFinder
All Implemented Interfaces:
ij.gui.DialogListener, ExtendedPlugInFilter, PlugInFilter

public class MaximumFinder
extends java.lang.Object
implements ExtendedPlugInFilter, ij.gui.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 ROIs, including non-rectangular ROIs. Since this plug-in creates a separate output image it processes only single images or slices, no stacks. 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 (Java2 required) version 07-Aug-2007 Michael Schmid. Fixed a bug that could delete particles when doing watershed segmentation of an EDM.


Nested Class Summary
(package private)  class MaximumFinder.MaxPoint
          Coordinates and the value of a local maximum.
 
Field Summary
static int COUNT
          Do not create an image, just count maxima and add count to Results table
(package private)  int[] dirOffset
           
(package private)  int[] dirXoffset
           
(package private)  int[] dirYoffset
           
(package private) static byte ELIMINATED
           
(package private) static byte EQUAL
           
static int IN_TOLERANCE
          Output type all points around the maximum within the tolerance
(package private) static int IS_DOT
           
(package private) static int IS_LINE
           
(package private) static byte LISTED
           
(package private) static byte MAX_AREA
           
(package private) static byte MAX_POINT
           
(package private) static byte MAXIMUM
          the following constants are used to set bits corresponding to pixel types
(package private) static byte[] outputTypeMasks
          type masks corresponding to the output types
(package private) static java.lang.String[] outputTypeNames
          output type names
static int POINT_SELECTION
          Do not create image, only mark points
(package private) static byte PROCESSED
           
static int SEGMENTED
          Output type watershed-segmented image
static 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, NO_CHANGES, NO_IMAGE_REQUIRED, NO_UNDO, PARALLELIZE_STACKS, ROI_REQUIRED, SNAPSHOT, STACK_REQUIRED, SUPPORTS_MASKING
 
Constructor Summary
MaximumFinder()
           
 
Method Summary
(package private)  void analyzeAndMarkMaxima(ImageProcessor ip, ByteProcessor typeP, MaximumFinder.MaxPoint[] maxPoints, boolean excludeEdgesNow, boolean isEDM, float globalMin, double tolerance)
          Check all maxima in list maxPoints, mark type of the points in typeP
(package private)  void cleanupExtraLines(ImageProcessor ip)
          Delete single dots and lines ending somewhere within a segmented particle Needed for post-processing watershed-segmented images that can have local minima
(package private)  void cleanupMaxima(ByteProcessor outIp, ByteProcessor typeP, MaximumFinder.MaxPoint[] maxPoints)
          eliminate unmarked maxima for use by watershed.
(package private)  void deleteEdgeParticles(ByteProcessor ip, ByteProcessor typeP)
          delete particles corresponding to edge maxima
(package private)  void deleteParticle(int x, int y, ByteProcessor ip, ij.gui.Wand wand)
          delete a particle (set from value 255 to current fill value).
 boolean dialogItemChanged(ij.gui.GenericDialog gd, java.awt.AWTEvent e)
          Read the parameters (during preview or after showing the dialog)
 ByteProcessor findMaxima(ImageProcessor ip, double tolerance, double threshold, int outputType, boolean excludeOnEdges, boolean isEDM)
          Here the processing is done: Find the maxima of an image (does not find minima)
(package private)  MaximumFinder.MaxPoint[] getSortedMaxPoints(ImageProcessor ip, ByteProcessor typeP, boolean excludeEdgesNow, boolean isEDM, float globalMin, double threshold)
          Find all local maxima (irrespective whether they finally qualify as maxima or not)
(package private)  int isLineOrDot(ImageProcessor ip, int x, int y)
          analyze the neighbors of a pixel (x, y) in a byte image; pixels <255 are considered part of lines.
(package private)  boolean isWithin(ImageProcessor ip, int x, int y, int direction)
          returns whether the neighbor in a given direction is within the image NOTE: it is assumed that the pixel x,y itself is within the image!
(package private)  ByteProcessor make8bit(ImageProcessor ip, ByteProcessor typeP, boolean isEDM, float globalMin, float globalMax, double threshold)
          Create an 8-bit image by scaling the pixel values of ip (background 0) and mark maximum areas as 255.
 void run(ImageProcessor ip)
          The plugin is inferred from ImageJ by this method
 void setNPasses(int nPasses)
          unused method required by interface ExtendedPlugInFilter
 int setup(java.lang.String arg, ImagePlus imp)
          Method to return types supported
 int showDialog(ImagePlus imp, java.lang.String command, PlugInFilterRunner pfr)
          This method is called after setup(arg, imp) unless the DONE flag has been set.
(package private)  int trueEdmHeight(int x, int y, ImageProcessor ip)
          Get estimated "true" height of a maximum or saddle point of a Euclidian Distance Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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

outputTypeNames

static final java.lang.String[] outputTypeNames
output type names


dirOffset

int[] dirOffset

dirXoffset

int[] dirXoffset

dirYoffset

int[] dirYoffset

IS_LINE

static final int IS_LINE
See Also:
Constant Field Values

IS_DOT

static final int IS_DOT
See Also:
Constant Field Values

MAXIMUM

static final byte MAXIMUM
the following constants are used to set bits corresponding to pixel types

See Also:
Constant Field Values

LISTED

static final byte LISTED
See Also:
Constant Field Values

PROCESSED

static final byte PROCESSED
See Also:
Constant Field Values

MAX_AREA

static final byte MAX_AREA
See Also:
Constant Field Values

EQUAL

static final byte EQUAL
See Also:
Constant Field Values

MAX_POINT

static final byte MAX_POINT
See Also:
Constant Field Values

ELIMINATED

static final byte ELIMINATED
See Also:
Constant Field Values

outputTypeMasks

static final byte[] outputTypeMasks
type masks corresponding to the output types

Constructor Detail

MaximumFinder

public MaximumFinder()
Method Detail

setup

public int setup(java.lang.String arg,
                 ImagePlus imp)
Method to return types supported

Specified by:
setup in interface PlugInFilter
Parameters:
arg - Not used by this plugin-filter
imp - 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 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(ij.gui.GenericDialog gd,
                                 java.awt.AWTEvent e)
Read the parameters (during preview or after showing the dialog)

Specified by:
dialogItemChanged in interface ij.gui.DialogListener

setNPasses

public void setNPasses(int nPasses)
unused method required by interface ExtendedPlugInFilter

Specified by:
setNPasses in interface ExtendedPlugInFilter

run

public void run(ImageProcessor ip)
The plugin is inferred from ImageJ by this method

Specified by:
run in interface PlugInFilter
Parameters:
ip - The image where maxima (or minima) should be found

findMaxima

public ByteProcessor findMaxima(ImageProcessor ip,
                                double tolerance,
                                double threshold,
                                int outputType,
                                boolean excludeOnEdges,
                                boolean isEDM)
Here the processing is done: Find the maxima of an image (does not find minima)

Parameters:
ip - The input image
tolerance - Height tolerance: maxima are accepted only if protruding more than this value from the ridge to a higher maximum
threshold - minimum height of a maximum (uncalibrated); for no minimum height set it to ImageProcessor.NO_THRESHOLD
outputType - What to mark in output image: SINGLE_POINTS, IN_TOLERANCE or SEGMENTED. No output image is created for output types POINT_SELECTION and COUNT.
excludeOnEdges - Whether to exclude edge maxima
isEDM - Whether the image is a 16-bit 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.

getSortedMaxPoints

MaximumFinder.MaxPoint[] getSortedMaxPoints(ImageProcessor ip,
                                            ByteProcessor typeP,
                                            boolean excludeEdgesNow,
                                            boolean isEDM,
                                            float globalMin,
                                            double threshold)
Find all local maxima (irrespective whether they finally qualify as maxima or not)

Parameters:
ip - The image to be analyzed
typeP - A byte image, same size as ip, where the maximum points are marked as MAXIMUM (do not use it as output: for rois, the points are shifted w.r.t. the input image)
excludeEdgesNow - Whether to exclude edge pixels
isEDM - Whether ip is a 16-bit Euclidian distance map
globalMin - The minimum value of the image or roi
threshold - The threshold (calibrated) below which no pixels are processed. Ignored if ImageProcessor.NO_THRESHOLD
Returns:
An array of x, y coordinates and heights, sorted by height. Returns null if the thread is interrupted. Note: Do not use the positions of the points marked as MAXIMUM in typeP, they are invalid for images with a roi.

analyzeAndMarkMaxima

void analyzeAndMarkMaxima(ImageProcessor ip,
                          ByteProcessor typeP,
                          MaximumFinder.MaxPoint[] maxPoints,
                          boolean excludeEdgesNow,
                          boolean isEDM,
                          float globalMin,
                          double tolerance)
Check all maxima in list maxPoints, mark type of the points in typeP

Parameters:
ip - the image to be analyzed
typeP - 8-bit image, here the point types are marked by type: MAX_POINT, etc.
maxPoints - input: a list of all local maxima, sorted by height
excludeEdgesNow - whether to avoid edge maxima
isEDM - whether ip is a 16-bit Euclidian distance map
globalMin - minimum pixel value in ip
tolerance - minimum pixel value difference for two separate maxima

make8bit

ByteProcessor make8bit(ImageProcessor ip,
                       ByteProcessor typeP,
                       boolean isEDM,
                       float globalMin,
                       float globalMax,
                       double threshold)
Create an 8-bit image by scaling the pixel values of ip (background 0) and mark maximum areas as 255. For use as input for watershed segmentation

Parameters:
ip - The original image that should be segmented
typeP - Pixel types in ip
isEDM - Whether ip is an Euclidian distance map
globalMin - The minimum pixel value of ip
globalMax - The maximum pixel value of ip
threshold - Pixels of ip below this value (calibrated) are considered background. Ignored if ImageProcessor.NO_THRESHOLD
Returns:
The 8-bit output image.

trueEdmHeight

int trueEdmHeight(int x,
                  int y,
                  ImageProcessor ip)
Get estimated "true" height of a maximum or saddle point of a Euclidian Distance Map. This is needed since the point sampled is not necessarily at the highest position. Note: for simplicity, in contrast to EDM we don't care about the Sqrt(5) distance here.

Parameters:
x - x-position of the point
y - y-position of the point
ip - the EDM (16-bit, scaling as defined in EDM class)
Returns:
estimated height

cleanupMaxima

void cleanupMaxima(ByteProcessor outIp,
                   ByteProcessor typeP,
                   MaximumFinder.MaxPoint[] maxPoints)
eliminate unmarked maxima for use by watershed. Starting from each previous maximum, explore the surrounding down to successively lower levels until a marked maximum is touched (or the plateau of a previously eliminated maximum leads to a marked maximum). Then set all the points above this value to this value

Parameters:
outIp - the image containing the pixel values
typeP - the types of the pixels are marked here
maxPoints - array containing the coordinates of all maxima that might be relevant

cleanupExtraLines

void cleanupExtraLines(ImageProcessor ip)
Delete single dots and lines ending somewhere within a segmented particle Needed for post-processing watershed-segmented images that can have local minima

Parameters:
ip - 8-bit image with background = 0, lines between 1 and 254 and segmented particles = 255

isLineOrDot

int isLineOrDot(ImageProcessor ip,
                int x,
                int y)
analyze the neighbors of a pixel (x, y) in a byte image; pixels <255 are considered part of lines.

Parameters:
ip -
x -
y -
Returns:
IS_LINE if pixel is part of a line, IS_DOT if a single dot

deleteEdgeParticles

void deleteEdgeParticles(ByteProcessor ip,
                         ByteProcessor typeP)
delete particles corresponding to edge maxima

Parameters:
typeP - Here the pixel types of the original image are noted, pixels with bit MAX_AREA at the edge are considered indicators of an edge maximum.
ip - the image resulting from watershed segmentaiton (foreground pixels, i.e. particles, are 255, background 0)

deleteParticle

void deleteParticle(int x,
                    int y,
                    ByteProcessor ip,
                    ij.gui.Wand wand)
delete a particle (set from value 255 to current fill value). Position x,y must be within the particle


isWithin

boolean isWithin(ImageProcessor ip,
                 int x,
                 int y,
                 int direction)
returns whether the neighbor in a given direction is within the image NOTE: it is assumed that the pixel x,y itself is within the image! Uses class variables width, height: dimensions of the image

Parameters:
x - x-coordinate of the pixel that has a neighbor in the given direction
y - y-coordinate of the pixel that has a neighbor in the given direction
direction - the direction from the pixel towards the neighbor (see makeDirectionOffsets)
Returns:
true if the neighbor is within the image (provided that x, y is within)