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:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmPowerWatershed extends AlgorithmBase
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 Classes Modifier and Type Class Description (package private) class
AlgorithmPowerWatershed.Lifo
(package private) class
AlgorithmPowerWatershed.Rbt
(package private) class
AlgorithmPowerWatershed.RbtElt
-
Field Summary
Fields Modifier and Type Field Description private int
algo
private double
epsilon
private boolean
error
private boolean
geod
private java.util.Vector<java.lang.Short>
index_labels
private java.util.Vector<java.lang.Integer>
index_seeds
private short[]
Indics
private static int
Kruskal
private int
MAX
private static int
Prim
private boolean
produceProbaImage
private static int
PW_qis2
(package private) RandomNumberGen
randomGen
private static byte
RBT_Black
private static byte
RBT_Red
private int
SIZE_MAX_PLATEAU
private boolean
testIndic
private boolean
testLifo
private boolean
testRbtInteractive
private boolean
testRbtRandom
-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmPowerWatershed(ModelImage destImg, ModelImage srcImg, int algo, java.util.Vector<java.lang.Integer> index_seeds, java.util.Vector<java.lang.Short> index_labels, boolean geod)
Constructs Power watershed algorithm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
BucketSort(int[] A, int[] I, int r, int N)
private void
BucketSortCroiss(int[] A, int[] I, int r, int N)
private int
color_standard_weights(ModelImage image, int[] weights, int[][] edges, java.util.Vector<java.lang.Integer> seeds, int size_seeds, boolean geod, boolean quicksort)
private int[]
color_standard_weights_PW(ModelImage image, int[] weights, int[][] edges, java.util.Vector<java.lang.Integer> seeds, int size_seeds, int[] maxi, boolean quicksort)
private void
compute_edges(int[][] edges, int rs, int cs, int ds)
private AlgorithmPowerWatershed.Lifo
CreeLifoVide(int taillemax)
private AlgorithmPowerWatershed.Rbt
CreeRbtVide(int taillemax)
(package private) int
element_find(int x, int[] Fth)
private int
element_link(int x, int y, int[] Rnk, int[] Fth)
private void
element_link_geod_dilate(int n, int p, int[] Fth, int[] G, int[] O)
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)
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)
void
finalize()
Prepares this class for destruction.private void
gageodilate_union_find(int[] F, int[] G, int[] O, int[][] edges, int rs, int cs, int ds, int max_weight, boolean quicksort)
private void
grey_weights(ModelImage image, int[] weights, int[][] edges, java.util.Vector<java.lang.Integer> seeds, int size_seeds, boolean geod, boolean quicksort)
private int[]
grey_weights_PW(ModelImage image, int[][] edges, java.util.Vector<java.lang.Integer> seeds, int size_seeds, int[] weights, boolean quicksort)
private void
IndicsInit(int Size)
private void
indicTest()
private boolean
IsSet(int x, int INDIC)
(package private) static void
LeftRotate(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
private void
LifoFlush(AlgorithmPowerWatershed.Lifo L)
private int
LifoPop(AlgorithmPowerWatershed.Lifo L)
private void
LifoPrint(AlgorithmPowerWatershed.Lifo L)
private void
LifoPush(AlgorithmPowerWatershed.Lifo L, int V)
private void
LifoTermine(AlgorithmPowerWatershed.Lifo L)
private void
lifoTest()
private boolean
LifoVide(AlgorithmPowerWatershed.Lifo L)
private void
merge_node(int e1, int e2, int[] Rnk, int[] Fth, float[][] proba, int nb_labels)
private void
MSF_Kruskal(int[][] edges, int[] weights, int max_weight, java.util.Vector<java.lang.Integer> seeds, java.util.Vector<java.lang.Short> labels, int size_seeds, int rs, int cs, int ds, int nblabels)
private void
MSF_Prim(int[][] edges, int[] weights, java.util.Vector<java.lang.Integer> seeds, java.util.Vector<java.lang.Short> labels, int size_seeds, int rs, int cs, int ds, int nblabels)
private int
neighbor(int i, int k, int rs, int cs, int ds)
private int
neighbor_edge(int i, int k, int rs, int cs, int ds)
private int
neighbor_edge_3D(int node1, int node2, int i, int k, int rs, int cs, int ds)
private int
neighbor_node_edge(int i, int k, int rs, int cs, int ds)
private int
Partitionner(int[] A, int[] I, int p, int r)
private int
Partitionner_dec(int[] A, int[] I, int p, int r)
(package private) int
Partitionner_inc(int[] A, int[] I, int p, int r)
private int
PartitionStochastique(int[] A, int[] I, int p, int r)
private int
PartitionStochastique_dec(int[] A, int[] I, int p, int r)
private int
PartitionStochastique_inc(int[] A, int[] I, int p, int r)
private void
PowerWatershed_q2(int[][] edges, int[] weights, int[] normal_weights, int max_weight, java.util.Vector<java.lang.Integer> seeds, java.util.Vector<java.lang.Short> labels, int size_seeds, int rs, int cs, int ds, int nb_labels, boolean quicksort, ModelImage img_proba)
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)
private void
RbtCopy(AlgorithmPowerWatershed.Rbt dest, AlgorithmPowerWatershed.Rbt src)
private void
RbtDelete(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z)
private AlgorithmPowerWatershed.RbtElt
RbtDeleteAux(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z)
private void
RbtDeleteFixup(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
private AlgorithmPowerWatershed.RbtElt
RbtInsert(AlgorithmPowerWatershed.Rbt T, double k, int d)
private AlgorithmPowerWatershed.RbtElt
RbtInsertAux(AlgorithmPowerWatershed.Rbt T, double k, int d)
(package private) void
RbtInsertSimple(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z)
private void
rbtInteractiveTest()
private AlgorithmPowerWatershed.RbtElt
RbtMaximum(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
private AlgorithmPowerWatershed.RbtElt
RbtMinimum(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
private int
RbtPopMin(AlgorithmPowerWatershed.Rbt T)
private void
RbtPrint(AlgorithmPowerWatershed.Rbt T)
private void
RbtPrintRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x, int niv)
private void
rbtRandomTest()
private void
RbtReAlloc(AlgorithmPowerWatershed.Rbt A)
private AlgorithmPowerWatershed.RbtElt
RbtSearch(AlgorithmPowerWatershed.Rbt T, double k)
private AlgorithmPowerWatershed.RbtElt
RbtSuccessor(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
void
RbtTermine(AlgorithmPowerWatershed.Rbt T)
private void
RbtTransRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.Rbt A, AlgorithmPowerWatershed.RbtElt x)
private boolean
RbtVide(AlgorithmPowerWatershed.Rbt T)
(package private) static void
RightRotate(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
void
runAlgorithm()
Starts the program.private void
Set(int x, int INDIC)
private void
TriEdges(int[][] index_edges, int M, int[] nb_same_edges)
private void
TriRapideStochastique(int[] A, int[] I, int p, int r)
private void
TriRapideStochastique_dec(int[] A, int[] I, int p, int r)
private void
TriRapideStochastique_inc(int[] A, int[] I, int p, int r)
private void
UnSet(int x, int INDIC)
private void
UnSetAll(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, windowOpened
-
Methods 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, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
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
private java.util.Vector<java.lang.Integer> index_seeds
-
index_labels
private java.util.Vector<java.lang.Short> 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 Detail
-
AlgorithmPowerWatershed
public AlgorithmPowerWatershed(ModelImage destImg, ModelImage srcImg, int algo, java.util.Vector<java.lang.Integer> index_seeds, java.util.Vector<java.lang.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 <= 255 for segmentation in n labelsgeod
- Geodesic reconstruction
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in 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:
runAlgorithm
in classAlgorithmBase
-
PowerWatershed_q2
private void PowerWatershed_q2(int[][] edges, int[] weights, int[] normal_weights, int max_weight, java.util.Vector<java.lang.Integer> seeds, java.util.Vector<java.lang.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, java.util.Vector<java.lang.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, java.util.Vector<java.lang.Integer> seeds, int size_seeds, int[] maxi, boolean quicksort)
-
MSF_Prim
private void MSF_Prim(int[][] edges, int[] weights, java.util.Vector<java.lang.Integer> seeds, java.util.Vector<java.lang.Short> labels, int size_seeds, int rs, int cs, int ds, int nblabels)
-
RbtPopMin
private int RbtPopMin(AlgorithmPowerWatershed.Rbt T)
-
RbtDeleteAux
private AlgorithmPowerWatershed.RbtElt RbtDeleteAux(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z)
-
RbtDeleteFixup
private void RbtDeleteFixup(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
-
LeftRotate
static void LeftRotate(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
-
RightRotate
static void RightRotate(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
-
RbtSuccessor
private AlgorithmPowerWatershed.RbtElt RbtSuccessor(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
-
RbtMinimum
private AlgorithmPowerWatershed.RbtElt RbtMinimum(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
-
RbtInsert
private AlgorithmPowerWatershed.RbtElt RbtInsert(AlgorithmPowerWatershed.Rbt T, double k, int d)
-
RbtInsertAux
private AlgorithmPowerWatershed.RbtElt RbtInsertAux(AlgorithmPowerWatershed.Rbt T, double k, int d)
-
RbtInsertSimple
void RbtInsertSimple(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z)
-
RbtReAlloc
private void RbtReAlloc(AlgorithmPowerWatershed.Rbt A)
-
RbtTransRec
private void RbtTransRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.Rbt A, AlgorithmPowerWatershed.RbtElt x)
-
RbtSearch
private AlgorithmPowerWatershed.RbtElt RbtSearch(AlgorithmPowerWatershed.Rbt T, double k)
-
RbtDelete
private void RbtDelete(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt z)
-
RbtMaximum
private AlgorithmPowerWatershed.RbtElt RbtMaximum(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x)
-
RbtVide
private boolean RbtVide(AlgorithmPowerWatershed.Rbt T)
-
RbtPrint
private void RbtPrint(AlgorithmPowerWatershed.Rbt T)
-
RbtPrintRec
private void RbtPrintRec(AlgorithmPowerWatershed.Rbt T, AlgorithmPowerWatershed.RbtElt x, int niv)
-
MSF_Kruskal
private void MSF_Kruskal(int[][] edges, int[] weights, int max_weight, java.util.Vector<java.lang.Integer> seeds, java.util.Vector<java.lang.Short> labels, int size_seeds, int rs, int cs, int ds, int nblabels)
-
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, java.util.Vector<java.lang.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, java.util.Vector<java.lang.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
private AlgorithmPowerWatershed.Lifo CreeLifoVide(int taillemax)
-
LifoPush
private void LifoPush(AlgorithmPowerWatershed.Lifo L, int V)
-
LifoVide
private boolean LifoVide(AlgorithmPowerWatershed.Lifo L)
-
LifoPop
private int LifoPop(AlgorithmPowerWatershed.Lifo L)
-
LifoTermine
private void LifoTermine(AlgorithmPowerWatershed.Lifo L)
-
LifoFlush
private void LifoFlush(AlgorithmPowerWatershed.Lifo L)
-
LifoPrint
private void LifoPrint(AlgorithmPowerWatershed.Lifo L)
-
CreeRbtVide
private AlgorithmPowerWatershed.Rbt CreeRbtVide(int taillemax)
-
RbtCopy
private void RbtCopy(AlgorithmPowerWatershed.Rbt dest, AlgorithmPowerWatershed.Rbt src)
-
RbtTermine
public void RbtTermine(AlgorithmPowerWatershed.Rbt T)
-
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)
-
-