Package gov.nih.mipav.model.algorithms
Class AlgorithmPowerWatershed
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmPowerWatershed
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
This is a port of C code written by Camille Couprie in 2009.
Camille Couprie has kindly granted the NIH MIPAV project permission to port her Power watershed code from C to Java
under a BSD license.
Porting performed by William Gandler.
This "powerwatershed" package provides implementation of several segmentation algorithms on 2D or 3D images.
The 3 algorithms are:
1.) Maximum Spanning Forest computed by Kruskal algorithm.
2.) Powerwatersheds (p=infinite, q= 2) : Maximum Spanning Forest computed by Kruskal algorithm and
Random walker on plateaus.
3.) Maximum Spanning Forest computed by Prim algorithm using red and black trees.
Reference: "Power watersheds: A new image segmentation framework extending graph cuts, random walker
and optimal spanning forest" by Camille Couprie, Leo Grady, Laurent Najman, and Hugues Talbot,
ICCV'09, 2009,
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) class(package private) classNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate doubleprivate booleanprivate booleanprivate short[]private static intprivate intprivate static intprivate booleanprivate static int(package private) RandomNumberGenprivate static byteprivate static byteprivate intprivate booleanprivate booleanprivate booleanprivate booleanFields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmPowerWatershed(ModelImage destImg, ModelImage srcImg, int algo, Vector<Integer> index_seeds, Vector<Short> index_labels, boolean geod) Constructs Power watershed algorithm. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidBucketSort(int[] A, int[] I, int r, int N) private voidBucketSortCroiss(int[] A, int[] I, int r, int N) private intcolor_standard_weights(ModelImage image, int[] weights, int[][] edges, Vector<Integer> seeds, int size_seeds, boolean geod, boolean quicksort) private int[]color_standard_weights_PW(ModelImage image, int[] weights, int[][] edges, Vector<Integer> seeds, int size_seeds, int[] maxi, boolean quicksort) private voidcompute_edges(int[][] edges, int rs, int cs, int ds) private AlgorithmPowerWatershed.LifoCreeLifoVide(int taillemax) private AlgorithmPowerWatershed.RbtCreeRbtVide(int taillemax) (package private) intelement_find(int x, int[] Fth) private intelement_link(int x, int y, int[] Rnk, int[] Fth) private voidelement_link_geod_dilate(int n, int p, int[] Fth, int[] G, int[] O) private booleanfill_A(double[] A_a, int[] A_indc, int[] A_indr, int[] A_nelem, int[] A_m, int[] A_n, int N, int M, int numb_boundary, int[][] index_edges, boolean[] seeded_vertex, int[] indic_sparse, int[] nb_same_edges) private voidfill_B(double[] B_a, int[] B_indc, int[] B_indr, int[] B_nelem, int[] B_m, int[] B_n, int N, int M, int numb_boundary, int[][] index_edges, boolean[] seeded_vertex, int[] indic_sparse, int[] nb_same_edges) voidfinalize()Prepares this class for destruction.private voidgageodilate_union_find(int[] F, int[] G, int[] O, int[][] edges, int rs, int cs, int ds, int max_weight, boolean quicksort) private voidgrey_weights(ModelImage image, int[] weights, int[][] edges, Vector<Integer> seeds, int size_seeds, boolean geod, boolean quicksort) private int[]grey_weights_PW(ModelImage image, int[][] edges, Vector<Integer> seeds, int size_seeds, int[] weights, boolean quicksort) private voidIndicsInit(int Size) private voidprivate booleanIsSet(int x, int INDIC) (package private) static voidprivate voidprivate intprivate voidprivate voidLifoPush(AlgorithmPowerWatershed.Lifo L, int V) private voidprivate voidlifoTest()private booleanprivate voidmerge_node(int e1, int e2, int[] Rnk, int[] Fth, float[][] proba, int nb_labels) private voidMSF_Kruskal(int[][] edges, int[] weights, int max_weight, Vector<Integer> seeds, Vector<Short> labels, int size_seeds, int rs, int cs, int ds, int nblabels) private voidMSF_Prim(int[][] edges, int[] weights, Vector<Integer> seeds, Vector<Short> labels, int size_seeds, int rs, int cs, int ds, int nblabels) private intneighbor(int i, int k, int rs, int cs, int ds) private intneighbor_edge(int i, int k, int rs, int cs, int ds) private intneighbor_edge_3D(int node1, int node2, int i, int k, int rs, int cs, int ds) private intneighbor_node_edge(int i, int k, int rs, int cs, int ds) private intPartitionner(int[] A, int[] I, int p, int r) private intPartitionner_dec(int[] A, int[] I, int p, int r) (package private) intPartitionner_inc(int[] A, int[] I, int p, int r) private intPartitionStochastique(int[] A, int[] I, int p, int r) private intPartitionStochastique_dec(int[] A, int[] I, int p, int r) private intPartitionStochastique_inc(int[] A, int[] I, int p, int r) private voidPowerWatershed_q2(int[][] edges, int[] weights, int[] normal_weights, int max_weight, Vector<Integer> seeds, Vector<Short> labels, int size_seeds, int rs, int cs, int ds, int nb_labels, boolean quicksort, ModelImage img_proba) private booleanRandomWalker(int[][] index_edges, int M, int[] index, int[] indic_vertex, int N, int[] index_seeds, float[][] boundary_values, int numb_boundary, int nb_labels, float[][] proba) private voidprivate voidprivate AlgorithmPowerWatershed.RbtEltprivate voidprivate AlgorithmPowerWatershed.RbtEltRbtInsert(AlgorithmPowerWatershed.Rbt T, double k, int d) private AlgorithmPowerWatershed.RbtEltRbtInsertAux(AlgorithmPowerWatershed.Rbt T, double k, int d) (package private) voidprivate voidprivate AlgorithmPowerWatershed.RbtEltprivate AlgorithmPowerWatershed.RbtEltprivate intprivate voidprivate voidRbtPrintRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x, int niv) private voidprivate voidprivate AlgorithmPowerWatershed.RbtEltRbtSearch(AlgorithmPowerWatershed.Rbt T, double k) private AlgorithmPowerWatershed.RbtEltvoidprivate voidRbtTransRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.Rbt A, AlgorithmPowerWatershed.RbtElt x) private boolean(package private) static voidvoidStarts the program.private voidSet(int x, int INDIC) private voidTriEdges(int[][] index_edges, int M, int[] nb_same_edges) private voidTriRapideStochastique(int[] A, int[] I, int p, int r) private voidTriRapideStochastique_dec(int[] A, int[] I, int p, int r) private voidTriRapideStochastique_inc(int[] A, int[] I, int p, int r) private voidUnSet(int x, int INDIC) private voidUnSetAll(int x) Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpenedMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
Kruskal
private static int Kruskal -
PW_qis2
private static int PW_qis2 -
Prim
private static int Prim -
RBT_Black
private static byte RBT_Black -
RBT_Red
private static byte RBT_Red -
epsilon
private double epsilon -
SIZE_MAX_PLATEAU
private int SIZE_MAX_PLATEAU -
testRbtInteractive
private boolean testRbtInteractive -
testRbtRandom
private boolean testRbtRandom -
testIndic
private boolean testIndic -
testLifo
private boolean testLifo -
algo
private int algo -
index_seeds
-
index_labels
-
geod
private boolean geod -
produceProbaImage
private boolean produceProbaImage -
error
private boolean error -
MAX
private int MAX -
Indics
private short[] Indics -
randomGen
RandomNumberGen randomGen
-
-
Constructor Details
-
AlgorithmPowerWatershed
public AlgorithmPowerWatershed(ModelImage destImg, ModelImage srcImg, int algo, Vector<Integer> index_seeds, Vector<Short> index_labels, boolean geod) Constructs Power watershed algorithm.- Parameters:
destImg- Image model where result image is to storedsrcImg- Source image modelalgo- Kruskal, or Primindex_seeds- The index in the image array of the seedindex_labels- For 2-labels 1 for white foreground and 2 for black background For multi-labels values from 1 to n with n invalid input: '<'= 255 for segmentation in n labelsgeod- Geodesic reconstruction
-
-
Method Details
-
finalize
public void finalize()Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
rbtInteractiveTest
private void rbtInteractiveTest() -
rbtRandomTest
private void rbtRandomTest() -
indicTest
private void indicTest() -
lifoTest
private void lifoTest() -
runAlgorithm
public void runAlgorithm()Starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-
PowerWatershed_q2
private void PowerWatershed_q2(int[][] edges, int[] weights, int[] normal_weights, int max_weight, Vector<Integer> seeds, Vector<Short> labels, int size_seeds, int rs, int cs, int ds, int nb_labels, boolean quicksort, ModelImage img_proba) -
RandomWalker
private boolean RandomWalker(int[][] index_edges, int M, int[] index, int[] indic_vertex, int N, int[] index_seeds, float[][] boundary_values, int numb_boundary, int nb_labels, float[][] proba) -
fill_A
private boolean fill_A(double[] A_a, int[] A_indc, int[] A_indr, int[] A_nelem, int[] A_m, int[] A_n, int N, int M, int numb_boundary, int[][] index_edges, boolean[] seeded_vertex, int[] indic_sparse, int[] nb_same_edges) -
fill_B
private void fill_B(double[] B_a, int[] B_indc, int[] B_indr, int[] B_nelem, int[] B_m, int[] B_n, int N, int M, int numb_boundary, int[][] index_edges, boolean[] seeded_vertex, int[] indic_sparse, int[] nb_same_edges) -
TriEdges
private void TriEdges(int[][] index_edges, int M, int[] nb_same_edges) -
TriRapideStochastique
private void TriRapideStochastique(int[] A, int[] I, int p, int r) -
PartitionStochastique
private int PartitionStochastique(int[] A, int[] I, int p, int r) -
Partitionner
private int Partitionner(int[] A, int[] I, int p, int r) -
merge_node
private void merge_node(int e1, int e2, int[] Rnk, int[] Fth, float[][] proba, int nb_labels) -
TriRapideStochastique_dec
private void TriRapideStochastique_dec(int[] A, int[] I, int p, int r) -
PartitionStochastique_dec
private int PartitionStochastique_dec(int[] A, int[] I, int p, int r) -
Partitionner_dec
private int Partitionner_dec(int[] A, int[] I, int p, int r) -
grey_weights_PW
private int[] grey_weights_PW(ModelImage image, int[][] edges, Vector<Integer> seeds, int size_seeds, int[] weights, boolean quicksort) -
color_standard_weights_PW
private int[] color_standard_weights_PW(ModelImage image, int[] weights, int[][] edges, Vector<Integer> seeds, int size_seeds, int[] maxi, boolean quicksort) -
MSF_Prim
-
RbtPopMin
-
RbtDeleteAux
private AlgorithmPowerWatershed.RbtElt RbtDeleteAux(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z) -
RbtDeleteFixup
-
LeftRotate
-
RightRotate
-
RbtSuccessor
private AlgorithmPowerWatershed.RbtElt RbtSuccessor(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x) -
RbtMinimum
private AlgorithmPowerWatershed.RbtElt RbtMinimum(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x) -
RbtInsert
-
RbtInsertAux
-
RbtInsertSimple
-
RbtReAlloc
-
RbtTransRec
private void RbtTransRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.Rbt A, AlgorithmPowerWatershed.RbtElt x) -
RbtSearch
-
RbtDelete
-
RbtMaximum
private AlgorithmPowerWatershed.RbtElt RbtMaximum(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x) -
RbtVide
-
RbtPrint
-
RbtPrintRec
-
MSF_Kruskal
-
neighbor
private int neighbor(int i, int k, int rs, int cs, int ds) -
BucketSort
private void BucketSort(int[] A, int[] I, int r, int N) -
element_link
private int element_link(int x, int y, int[] Rnk, int[] Fth) -
grey_weights
private void grey_weights(ModelImage image, int[] weights, int[][] edges, Vector<Integer> seeds, int size_seeds, boolean geod, boolean quicksort) -
compute_edges
private void compute_edges(int[][] edges, int rs, int cs, int ds) -
color_standard_weights
private int color_standard_weights(ModelImage image, int[] weights, int[][] edges, Vector<Integer> seeds, int size_seeds, boolean geod, boolean quicksort) -
neighbor_node_edge
private int neighbor_node_edge(int i, int k, int rs, int cs, int ds) -
gageodilate_union_find
private void gageodilate_union_find(int[] F, int[] G, int[] O, int[][] edges, int rs, int cs, int ds, int max_weight, boolean quicksort) -
element_link_geod_dilate
private void element_link_geod_dilate(int n, int p, int[] Fth, int[] G, int[] O) -
element_find
int element_find(int x, int[] Fth) -
neighbor_edge_3D
private int neighbor_edge_3D(int node1, int node2, int i, int k, int rs, int cs, int ds) -
neighbor_edge
private int neighbor_edge(int i, int k, int rs, int cs, int ds) -
TriRapideStochastique_inc
private void TriRapideStochastique_inc(int[] A, int[] I, int p, int r) -
PartitionStochastique_inc
private int PartitionStochastique_inc(int[] A, int[] I, int p, int r) -
Partitionner_inc
int Partitionner_inc(int[] A, int[] I, int p, int r) -
BucketSortCroiss
private void BucketSortCroiss(int[] A, int[] I, int r, int N) -
CreeLifoVide
-
LifoPush
-
LifoVide
-
LifoPop
-
LifoTermine
-
LifoFlush
-
LifoPrint
-
CreeRbtVide
-
RbtCopy
-
RbtTermine
-
IndicsInit
private void IndicsInit(int Size) -
Set
private void Set(int x, int INDIC) -
UnSet
private void UnSet(int x, int INDIC) -
IsSet
private boolean IsSet(int x, int INDIC) -
UnSetAll
private void UnSetAll(int x)
-