public class SioxSegmentator extends Object
To segmentate an image one has to perform the following steps.
SioxSegmentator
.
segmentate
on the image with the confidence
matrix. This stores the result as new foreground confidence into
the confidence matrix, with each entry being either
zero (CERTAIN_BACKGROUND_CONFIDENCE
) or one
(CERTAIN_FOREGROUND_CONFIDENCE
).
subpixelRefine
to areas
where pixels contain both foreground and background (e.g.
object borders or highly detailed features like flowing hairs).
The pixel are then assigned confidence values between zero and
one to give them a measure of "foregroundness".
This step may be repeated as often as needed.
For algorithm documentation refer to
G. Friedland, K. Jantz, L. Knipping, R. Rojas:
Image Segmentation by Uniform Color Clustering
-- Approach and Benchmark Results,
Technical Report B-05-07,
Department of Computer Science, Freie Universitaet Berlin, June 2005.
See http://www.siox.org for more information.
Algorithm idea by Gerald Friedland.
Modifier and Type | Field and Description |
---|---|
static String |
ADD_EDGE
Add mode for the subpixel refinement.
|
static float |
BACKGROUND_CONFIDENCE
Confidence for a region likely being background.
|
static float |
CERTAIN_BACKGROUND_CONFIDENCE
Confidence corresponding to a certain background region (equals zero).
|
static float |
CERTAIN_FOREGROUND_CONFIDENCE
Confidence corresponding to a certain foreground region (equals one).
|
static float |
FOREGROUND_CONFIDENCE
Confidence for a region likely being foreground.
|
static String |
SUB_EDGE
Subtract mode for the subpixel refinement.
|
static float |
UNKNOWN_REGION_CONFIDENCE
Confidence for foreground or background type being equally likely.
|
Constructor and Description |
---|
SioxSegmentator(int w,
int h,
float[] limits)
Constructs a SioxSegmentator Object to be used for image segmentation.
|
SioxSegmentator(int w,
int h,
float[] limits,
float[][] bgSignature,
float[][] fgSignature)
Constructs a SioxSegmentator Object to be used for image segmentation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
applyPrecomputedSignatures(int[] image,
float[] cm,
int smoothness,
double sizeFactorToKeep)
Segments the given image with the previously calculated color signatures.
|
float[][] |
getBgSignature()
Get background signature
|
float[][] |
getFgSignature()
Get foreground signature
|
protected void |
keepOnlyLargeComponents(float[] cm,
float threshold,
double sizeFactorToKeep)
Clears given confidence matrix except entries for the largest connected
component and every component with
size*sizeFactorToKeep >= sizeOfLargestComponent . |
protected void |
keepOnlyLargeComponents(float[] cm,
float threshold,
double sizeFactorToKeep,
IntArrayList predefinedFgPixels)
Clears given confidence matrix except entries for the user-defined connected
component and every component with
size*sizeFactorToKeep >= sizeOfLargestComponent . |
boolean |
segmentate(int[] image,
float[] cm,
int smoothness,
double sizeFactorToKeep)
Segments the given image with information from the confidence
matrix.
|
boolean |
segmentatevideo_firstframe(int[] image,
float[] cm,
double sizeFactorToKeep)
Segments the first frame of a scene in a video.
|
boolean |
segmentatevideo_nextframe(int[] image,
float[] cm,
double sizeFactorToKeep)
Segment the further frames of a scene in a video.
|
void |
subpixelRefine(Area area,
String brushmode,
float threshold,
float[] cf)
Refines the classification stored in the confidence matrix by modifying
the confidences for regions which have characteristics to both
foreground and background if they fall into the specified area.
|
void |
subpixelRefine(int x,
int y,
String brushmode,
float threshold,
float[] cf,
int brushsize)
Refines the classification stored in the confidence matrix by modifying
the confidences for regions which have characteristics to both
foreground and background if they fall into the specified square.
|
public static final String ADD_EDGE
public static final String SUB_EDGE
public static final float CERTAIN_FOREGROUND_CONFIDENCE
public static final float FOREGROUND_CONFIDENCE
public static final float UNKNOWN_REGION_CONFIDENCE
public static final float BACKGROUND_CONFIDENCE
public static final float CERTAIN_BACKGROUND_CONFIDENCE
public SioxSegmentator(int w, int h, float[] limits)
w
- X resolution of the image to be segmented.h
- Y resolution of the image to be segmented.limits
- Size of the cluster on LAB axises.
If null
, the default value {0.64f,1.28f,2.56f}
is used.public SioxSegmentator(int w, int h, float[] limits, float[][] bgSignature, float[][] fgSignature)
w
- X resolution of the image to be segmented.h
- Y resolution of the image to be segmented.limits
- Size of the cluster on LAB axises.
If null
, the default value {0.64f,1.28f,2.56f}
is used.bgSignature
- background color signaturefgSignature
- foreground color signaturepublic boolean segmentate(int[] image, float[] cm, int smoothness, double sizeFactorToKeep)
The confidence entries of BACKGROUND_CONFIDENCE
or less
are mark known background pixel for the segmentation, those
of at least FOREGROUND_CONFIDENCE
mark known
foreground pixel for the segmentation. Any other entry is treated
as region of unknown affiliation.
As result, each pixel is classified either as foreground or
background, stored back into its cm
entry as confidence
CERTAIN_FOREGROUND_CONFIDENCE
or
CERTAIN_BACKGROUND_CONFIDENCE
.
image
- Pixel data of the image to be segmented.
Every integer represents one ARGB-value.cm
- Confidence matrix specifying the probability of an image
belonging to the foreground before and after the segmentation.smoothness
- Number of smoothing steps in the post processing.sizeFactorToKeep
- Segmentation retains the largest connected
foreground component plus any component with size at least
sizeOfLargestComponent/sizeFactorToKeep
.true
if the segmentation algorithm succeeded,
false
if segmentation is impossibleIllegalStateException
- if the confidence matrix defines no
image foreground.public boolean applyPrecomputedSignatures(int[] image, float[] cm, int smoothness, double sizeFactorToKeep)
image
- Pixel data of the image to be segmented.
Every integer represents one ARGB-value.cm
- Confidence matrix specifying the probability of an image
belonging to the foreground before and after the segmentation.smoothness
- Number of smoothing steps in the post processing.sizeFactorToKeep
- Segmentation retains the largest connected
foreground component plus any component with size at least
sizeOfLargestComponent/sizeFactorToKeep
.true
if the segmentation algorithm succeeded,
false
if segmentation is impossibleIllegalStateException
- if the confidence matrix defines no
image foreground.public boolean segmentatevideo_firstframe(int[] image, float[] cm, double sizeFactorToKeep)
The confidence entries of BACKGROUND_CONFIDENCE
or less
are mark known background pixel for the segmentation, those
of at least FOREGROUND_CONFIDENCE
mark known
foreground pixel for the segmentation. Any other entry is treated
as region of unknown affiliation.
As result, each pixel is classified either as foreground or
background, stored back into its cm
entry as confidence
CERTAIN_FOREGROUND_CONFIDENCE
or
CERTAIN_BACKGROUND_CONFIDENCE
.
image
- Pixel data of the image to be segmented.
Every integer represents one ARGB-value.cm
- Confidence matrix specifying the probability of an image
belonging to the foreground before and after the segmentation.sizeFactorToKeep
- Segmentation retains the largest connected
foreground component plus any component with size at least
sizeOfLargestComponent/sizeFactorToKeep
.true
if the segmentation algorithm succeeded,
false
if segmentation is impossibleIllegalStateException
- if the confidence matrix defines no
image foreground.public boolean segmentatevideo_nextframe(int[] image, float[] cm, double sizeFactorToKeep)
The confidence entries of BACKGROUND_CONFIDENCE
or less
are mark known background pixel for the segmentation, those
of at least FOREGROUND_CONFIDENCE
mark known
foreground pixel for the segmentation. Any other entry is treated
as region of unknown affiliation. This method does not require any known
confidences in a frame.
As result, each pixel is classified either as foreground or
background, stored back into its cm
entry as confidence
CERTAIN_FOREGROUND_CONFIDENCE
or
CERTAIN_BACKGROUND_CONFIDENCE
.
image
- Pixel data of the image to be segmented.
Every integer represents one ARGB-value.cm
- Confidence matrix specifying the probability of an image
belonging to the foreground before and after the segmentation.sizeFactorToKeep
- Segmentation retains the largest connected
foreground component plus any component with size at least
sizeOfLargestComponent/sizeFactorToKeep
.true
if the segmentation algorithm succeeded,
false
if segmentation is impossibleIllegalStateException
- if no color signature has been defined
before calling this method.protected void keepOnlyLargeComponents(float[] cm, float threshold, double sizeFactorToKeep)
size*sizeFactorToKeep >= sizeOfLargestComponent
.cm
- Confidence matrix to be analyzedthreshold
- Pixel visibility threshold.
Exactly those cm entries larger than threshold are considered
to be a "visible" foreground pixel.sizeFactorToKeep
- This method keeps the largest connected
component plus any component with size at least
sizeOfLargestComponent/sizeFactorToKeep
.protected void keepOnlyLargeComponents(float[] cm, float threshold, double sizeFactorToKeep, IntArrayList predefinedFgPixels)
size*sizeFactorToKeep >= sizeOfLargestComponent
.cm
- Confidence matrix to be analyzedthreshold
- Pixel visibility threshold.
Exactly those cm entries larger than threshold are considered
to be a "visible" foreground pixel.sizeFactorToKeep
- This method keeps the largest connected
component plus any component with size at least
sizeOfLargestComponent/sizeFactorToKeep
.predefinedFgPixels
- list of pixels defined for the user as foreground.public void subpixelRefine(int x, int y, String brushmode, float threshold, float[] cf, int brushsize)
The can be used in displaying the image by assigning the alpha values of the pixels according to the confidence entries.
In the algorithm descriptions and examples GUIs this step is referred to as Detail Refinement (Brush).
x
- Horizontal coordinate of the squares center.y
- Vertical coordinate of the squares center.brushmode
- Mode of the refinement applied, ADD_EDGE
or SUB_EDGE
. Add mode only modifies pixels
formerly classified as background, sub mode only those
formerly classified as foreground.threshold
- Threshold for the add and sub refinement, deciding
at the confidence level to stop at.cf
- The confidence matrix to modify, generated by
segmentate
, possibly already refined by previous
calls to subpixelRefine
.brushsize
- Halfed diameter of the square shaped brush.IllegalStateException
- if there is no segmentation calculated
yet to be refinedsegmentate(int[], float[], int, double)
public void subpixelRefine(Area area, String brushmode, float threshold, float[] cf)
The can be used in displaying the image by assigning the alpha values of the pixels according to the confidence entries.
In the algorithm descriptions and examples GUIs this step is referrered to as Detail Refinement (Brush).
area
- Area in which the reworking of the segmentation is
applied to.brushmode
- Mode of the refinement applied, ADD_EDGE
or SUB_EDGE
. Add mode only modifies pixels
formerly classified as background, sub mode only those
formerly classified as foreground.threshold
- Threshold for the add and sub refinement, deciding
at the confidence level to stop at.cf
- The confidence matrix to modify, generated by
segmentate
, possibly already refined by privious
calls to subpixelRefine
.IllegalStateException
- if there is no segmentation
calculated yet to be refinedsegmentate(int[], float[], int, double)
public float[][] getBgSignature()
public float[][] getFgSignature()
Copyright © 2015–2021 Fiji. All rights reserved.