br.usp.ime.klava.segmentit.structures
Class HierarchyManager

java.lang.Object
  extended by br.usp.ime.klava.segmentit.structures.HierarchyManager

public class HierarchyManager
extends java.lang.Object

Manages hierarchical operations over an image.

Author:
Bruno Klava

Constructor Summary
HierarchyManager(PrimitiveCatchmentBasinsGraph graph, HierarchyCriterion hierarchyCriterion, java.awt.image.BufferedImage originalImage)
          Constructs a hierarchical set of nested partitions of graph.
HierarchyManager(PrimitiveCatchmentBasinsGraph graph, HierarchyCriterion hierarchyCriterion, int[] labels, java.awt.Point selectedPixel, java.awt.image.BufferedImage originalImage)
          Constructs a hierarchical set of nested partitions of graph.
HierarchyManager(PrimitiveCatchmentBasinsGraph graph, HierarchyCriterion hierarchyCriterion, Pixel[][] initialPartition, java.awt.Point selectedPixel, java.awt.image.BufferedImage originalImage)
          Constructs a hierarchical set of nested partitions of the vertices of the graph.
 
Method Summary
 boolean belongsToEnabledRegion(int x, int y)
          Returns if the pixel located at (x,y) belongs to the region where the hierarchy operations are restricted to.
 int[] getActiveLabels()
          Returns the active labels of each leaf node of the hierarchy.
 int getEdgeWeightIndex(int weight)
          Returns the index of the given weight in the array of existing edges weights.
 PrimitiveCatchmentBasinsGraph getGraphFromFilteredImage()
          Returns the PrimitiveCatchmentBasinsGraph derived from the filtered imaged used in this HierarchyManager.
 HierarchyNode getHierarchyRoot()
          Returns the root node of the hierarchy.
 java.awt.image.BufferedImage getMarkersImage()
          Returns markers that recovers exactly the selected partition when applied back on the RAG.
 int[] getTCLWeights()
          Returns the weights of the edges in the hierarchy.
 int getWeight(int index)
          Returns the hierarchy weight associated with index
 boolean isMergeEnabled(int x, int y)
          Returns if the merge local operation is available for the current active region that contains the pixel located at (x,y ).
 boolean isRefineEnabled(int x, int y)
          Returns if the split local operation is available in the current active region that contains the pixel located at (x,y ).
 boolean isRootActive()
          Returns if the hierarchy root is active (the selected partitions is the coarsest possible).
 HierarchyNode merge(int x, int y)
          Merges the region that contains the pixel located at (x, y).
 java.awt.image.BufferedImage paintSelectedPartition()
          Returns an image with the selected partition painted.
 java.awt.image.BufferedImage paintSelectedPartition(HierarchyNode hierarchyNode)
          Returns an image with the selected partition painted.
 void randomizeColors()
          Randomizes the Colors of the underlying TreeOfCriticalLakes.
 HierarchyState redo()
          Redoes an action, if possible.
 HierarchyNode refine(int x, int y)
          Splits the region that contains the pixel located at (x, y).
 void setCriterion(HierarchyCriterion hierarchyCriterion, boolean storeState)
          Derives a nested partitions set using the given hierarchyCriterion.
 void setDisplayOnlySelectedRegion(boolean displayOnlySelectedRegion)
          Sets if only the region where the operation are restricted to should be displayed.
 void setThreshold(int threshold, boolean storeState)
          Selects a partition on the hierarchy according to a threshold value.
static void setTreeOfCriticalLakesBuilder(TreeOfCriticalLakesBuilderIF treeOfCriticalLakesBuilder)
          Sets a TreeOfCriticalLakesBuilderIF to build TreeOfCriticalLakes in this HierarchyManager
 HierarchyState undo()
          Undoes an action, if possible.
 void weldLabels(java.util.Collection<java.lang.Integer> labelsToWeld)
          Welds the regions whose labels are in labelsToWeld.
 boolean weldMarkedPixels(java.lang.Boolean[][] markedPixels)
          Welds the regions that contains any markedPixels.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HierarchyManager

public HierarchyManager(PrimitiveCatchmentBasinsGraph graph,
                        HierarchyCriterion hierarchyCriterion,
                        Pixel[][] initialPartition,
                        java.awt.Point selectedPixel,
                        java.awt.image.BufferedImage originalImage)
                 throws ColorImageException
Constructs a hierarchical set of nested partitions of the vertices of the graph.

Parameters:
graph - a PrimitiveCatchmentBasinsGraph from which the hierarchy will be built
hierarchyCriterion - the criterion from which the partitions are derived
initialPartition - a partition desired to be localized at the hierarchy
selectedPixel - the coordinates of a pixel of the region of initialPartition which the operations will be restricted to
originalImage - the original image
Throws:
ColorImageException - if originalImage is not a gray level image and the hierarchyCriterion do not support color images

HierarchyManager

public HierarchyManager(PrimitiveCatchmentBasinsGraph graph,
                        HierarchyCriterion hierarchyCriterion,
                        int[] labels,
                        java.awt.Point selectedPixel,
                        java.awt.image.BufferedImage originalImage)
                 throws ColorImageException
Constructs a hierarchical set of nested partitions of graph.

Parameters:
graph - a graph of primitive catchment basins from which the hierarchy will be built
hierarchyCriterion - the criterion from which the partitions are derived
labels - a labeling that corresponds to a partition desired to be localized at the hierarchy
selectedPixel - a pixel of the region of initialPartition which the operations will be restricted to
originalImage - the original image
Throws:
ColorImageException - if originalImage is not a gray level image and the hierarchyCriterion do not support color images

HierarchyManager

public HierarchyManager(PrimitiveCatchmentBasinsGraph graph,
                        HierarchyCriterion hierarchyCriterion,
                        java.awt.image.BufferedImage originalImage)
                 throws ColorImageException
Constructs a hierarchical set of nested partitions of graph.

Parameters:
graph - a graph of primitive catchment basins from which the hierarchy will be built
hierarchyCriterion - the criterion from which the partitions are derived
originalImage - the original image
Throws:
ColorImageException - if originalImage is not a gray level image and the hierarchyCriterion do not support color images
Method Detail

weldMarkedPixels

public boolean weldMarkedPixels(java.lang.Boolean[][] markedPixels)
Welds the regions that contains any markedPixels.

Parameters:
markedPixels - Boolean matrix indicating which pixels are marked

weldLabels

public void weldLabels(java.util.Collection<java.lang.Integer> labelsToWeld)
Welds the regions whose labels are in labelsToWeld.

Parameters:
labelsToWeld - the labels of the regions to be welded

setCriterion

public void setCriterion(HierarchyCriterion hierarchyCriterion,
                         boolean storeState)
Derives a nested partitions set using the given hierarchyCriterion.

Parameters:
hierarchyCriterion - a HierarchyCriterion from which the partitions are derived
storeState - if the new state must be store for undo/redo

setThreshold

public void setThreshold(int threshold,
                         boolean storeState)
Selects a partition on the hierarchy according to a threshold value.

Parameters:
threshold - the threshold value to select a partition in the hierarchy
storeState - if the new state must be store for undo/redo

getActiveLabels

public int[] getActiveLabels()
Returns the active labels of each leaf node of the hierarchy.

Returns:
the active labels of each leaf node of the hierarchy

paintSelectedPartition

public java.awt.image.BufferedImage paintSelectedPartition()
Returns an image with the selected partition painted.

Returns:
an image with the selected partition painted

paintSelectedPartition

public java.awt.image.BufferedImage paintSelectedPartition(HierarchyNode hierarchyNode)
Returns an image with the selected partition painted.

Parameters:
hierarchyNode - the HierarchyNode that needs to be painted
Returns:
an image with the selected partition painted

refine

public HierarchyNode refine(int x,
                            int y)
Splits the region that contains the pixel located at (x, y).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
the HierarchyNode that was refined, null if the refine operation was not enabled

isRefineEnabled

public boolean isRefineEnabled(int x,
                               int y)
Returns if the split local operation is available in the current active region that contains the pixel located at (x,y ).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
true if the split local operation is available for the current active region that contains the pixel located at ( x,y)

merge

public HierarchyNode merge(int x,
                           int y)
Merges the region that contains the pixel located at (x, y).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
the HierarchyNode selected by this merging operation, null if the merge operation was not enabled

isMergeEnabled

public boolean isMergeEnabled(int x,
                              int y)
Returns if the merge local operation is available for the current active region that contains the pixel located at (x,y ).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
true if the merge local operation is available for the current active region that contains the pixel located at ( x,y)

belongsToEnabledRegion

public boolean belongsToEnabledRegion(int x,
                                      int y)
Returns if the pixel located at (x,y) belongs to the region where the hierarchy operations are restricted to.

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
true if the pixel located at (x, y) belongs to the region where the hierarchy operations are restricted to

getMarkersImage

public java.awt.image.BufferedImage getMarkersImage()
Returns markers that recovers exactly the selected partition when applied back on the RAG.

Returns:
markers that recovers exactly the selected partition when applied back on the RAG

setDisplayOnlySelectedRegion

public void setDisplayOnlySelectedRegion(boolean displayOnlySelectedRegion)
Sets if only the region where the operation are restricted to should be displayed.

Parameters:
displayOnlySelectedRegion - true if only the region where the operation are restricted to should be displayed

undo

public HierarchyState undo()
Undoes an action, if possible.

Returns:
the current state, null if not action was undone.

redo

public HierarchyState redo()
Redoes an action, if possible.

Returns:
the current state, null if not action was redone.

isRootActive

public boolean isRootActive()
Returns if the hierarchy root is active (the selected partitions is the coarsest possible).

Returns:
if the hierarchy root is active

getTCLWeights

public int[] getTCLWeights()
Returns the weights of the edges in the hierarchy.

Returns:
the weights of the edges in the hierarchy

getWeight

public int getWeight(int index)
Returns the hierarchy weight associated with index

Parameters:
index - the order of the desired weight in the ordered weights
Returns:
the hierarchy weight associated with index

getEdgeWeightIndex

public int getEdgeWeightIndex(int weight)
Returns the index of the given weight in the array of existing edges weights.

Parameters:
weight - the weight of an edge
Returns:
the index of the given weight in the array of existing edges weights, or a negative int if there is none edge whose weight is equal to weight

getHierarchyRoot

public HierarchyNode getHierarchyRoot()
Returns the root node of the hierarchy.

Returns:
the root node of the hierarchy

getGraphFromFilteredImage

public PrimitiveCatchmentBasinsGraph getGraphFromFilteredImage()
Returns the PrimitiveCatchmentBasinsGraph derived from the filtered imaged used in this HierarchyManager.

Returns:
the PrimitiveCatchmentBasinsGraph used in this HierarchyManager

randomizeColors

public void randomizeColors()
Randomizes the Colors of the underlying TreeOfCriticalLakes.


setTreeOfCriticalLakesBuilder

public static void setTreeOfCriticalLakesBuilder(TreeOfCriticalLakesBuilderIF treeOfCriticalLakesBuilder)
Sets a TreeOfCriticalLakesBuilderIF to build TreeOfCriticalLakes in this HierarchyManager

Parameters:
treeOfCriticalLakesBuilder - an implementation of TreeOfCriticalLakesBuilderIF