public class RandomWalkSegmentation extends Object
Available use cases are:
RandomWalkOptions
class. This class also contains some pre- and post-processing settings used by
RandomWalkSegmentation
object. Default constructor sets recommended values to all numeric
options skipping those related to pre- post-processing objects.
QuimPArrayUtils.imageProcessor2RealMatrix(ImageProcessor)
and
QuimPArrayUtils.realMatrix2ImageProcessor(RealMatrix)
.
RandomWalkSegmentation
uses Seeds
structure to store information about foreground
(FG) and background (BG) seeds. Initially these seeds can be provided in different formats such
as:
Color.RED
and BG is Color.GREEN
. In this mode
only these two seeds can be stored.
Seeds
(the only accepted input by
run(Seeds)
by numerous methods from SeedProcessor
. The
Seeds
contains two keys important for segmentation, RandomWalkSegmentation.SeedTypes.FOREGROUNDS
and
RandomWalkSegmentation.SeedTypes.BACKGROUND
, RandomWalkSegmentation.SeedTypes.FOREGROUNDS
is mandatory whereas
RandomWalkSegmentation.SeedTypes.BACKGROUND
can be empty. Along one key seeds are stored as separate
binary
images that contain only pixels that belong to specified seed (e.g. red color for RGB or
specified grayscale for multi-cell segmentation). The optionl key RandomWalkSegmentation.SeedTypes.ROUGHMASK
contains one binary image that stands for initial estimation of object larger than the object. It
is used by local mean feature only (RandomWalkOptions.useLocalMean
set true).
run(Seeds)
method. For RGB seeds FG and BG are always defined but if the input is
converted from grayscale image, RandomWalkSegmentation.SeedTypes.BACKGROUND
in Seeds
is empty. The
method returns probability maps ProbabilityMaps
that are organised similarly to
Seeds
. Again for multi-cell segmentation returned ProbabilityMaps
may not contain
RandomWalkSegmentation.SeedTypes.BACKGROUND
key. The algorithm assumes that background is on probability 0 and
it is Color.BLACK
. Probabilities are compared in compare(ProbabilityMaps)
method that returns 2d matrix being an output image.
Here is brief look for run(Seeds)
method activity:
Sequence diagram of run(Seeds)
giving the order of called methods:
See: src/test/Resources-static/Matlab/rw_laplace4.m
Modifier and Type | Class and Description |
---|---|
static class |
RandomWalkSegmentation.SeedTypes
Define foreground and background indexes enums with numerical indexes.
|
Modifier and Type | Field and Description |
---|---|
static int |
BOTTOM
Direction of circshift coded as in Matlab.
|
static int |
LEFT
Direction of circshift coded as in Matlab.
|
static int |
RIGHT
Direction of circshift coded as in Matlab.
|
static int |
TOP
Direction of circshift coded as in Matlab.
|
Constructor and Description |
---|
RandomWalkSegmentation(ij.process.ImageProcessor ip,
RandomWalkOptions params)
Construct segmentation object from ImageProcessor.
|
RandomWalkSegmentation(RealMatrix image,
RandomWalkOptions params)
Construct segmentation object from 2D RealMatrix representing image.
|
Modifier and Type | Method and Description |
---|---|
protected double |
getMeanSeedGlobal(List<Point> seeds)
Compute mean value from image only seeded pixels.
|
protected RealMatrix |
getMeanSeedLocal(ij.process.ImageProcessor mask,
int localMeanMaskSize)
Calculate local mean intensity for input image but only for areas masked by specified mask.
|
ProbabilityMaps |
getProbabilityMaps()
Return probability maps for each object (foreground is last).
|
ij.process.ImageProcessor |
run(Seeds seeds)
Main runner, does segmentation.
|
protected ProbabilityMaps |
solver(Seeds seeds,
RealMatrix[] gradients)
Run Random Walk segmentation.
|
public static final int RIGHT
public static final int LEFT
public static final int TOP
public static final int BOTTOM
public RandomWalkSegmentation(ij.process.ImageProcessor ip, RandomWalkOptions params) throws RandomWalkException
ip
- image to segmentparams
- parametersRandomWalkException
- on wrong image formatpublic RandomWalkSegmentation(RealMatrix image, RandomWalkOptions params)
It is assumed that this input image is 8-bit. Use
RandomWalkSegmentation(ImageProcessor, RandomWalkOptions)
for support 8 and 16-bit
images.
Passing wrong image can have effect to results as solver(Seeds, RealMatrix[])
normalises
image intensities to maximal theoretical intensity. See
setMaxTheoreticalIntSqr(ImageProcessor)
and solver(Seeds, RealMatrix[])
image
- image to segmentparams
- parameterspublic ij.process.ImageProcessor run(Seeds seeds) throws RandomWalkException
Requires defined FOREGROUNDS seeds and one BACKGROUND. If background is not given it assumes
during weighting (compare(ProbabilityMaps)
) background probability map with
probability 0. IT should wor even if there is only one seed FG and no BG because most arrays
are 0-filled by default.
seeds
- Seed arrays from SeedProcessor
RandomWalkException
- On wrong seedsprotected double getMeanSeedGlobal(List<Point> seeds)
seeds
- coordinates of points used to calculate their mean intensitySeeds#convertToList(SeedTypes)
protected RealMatrix getMeanSeedLocal(ij.process.ImageProcessor mask, int localMeanMaskSize)
The mean over segmented image intensity is evaluated within square window of configurable size and only for those pixels that are masked by binary mask given to this method. Mean is calculated respectfully to the number of masked pixels within window. Window is moved over the whole image.
This method works similarly to the convolution with the difference that the kernel is normalised for each position of the window to the number of masked pixels (within it). If for any position of the window there are no masked pixels inside, value 0.0 is set as result.
mask
- Binary mask of segmented image. Mask must contain only pixels with intensity 0 or
255 (according to definition of binary image in IJ)localMeanMaskSize
- Odd size of kernelprotected ProbabilityMaps solver(Seeds seeds, RealMatrix[] gradients)
The activity diagram for solver is as follows:
Note 1: that solver treats FG and BG seeds like equal objects. There is no difference between foreground and background seeds.
Note 2:number of iterations for BG object is limited to maximum number of iterations that occurred for FG objects.
seeds
- seed array returned from SeedProcessor
gradients
- pre-computed gradients returned from precomputeGradients()
Seeds
) or may
not contain BG map.public ProbabilityMaps getProbabilityMaps()
Copyright © 2002–2019 Department of Computer Science, Warwick University. All rights reserved.