de.unihalle.informatik.MiToBo.core.datatypes
Class MTBNeuriteSkelGraph

java.lang.Object
  extended by de.unihalle.informatik.MiToBo.core.datatypes.MTBGraph
      extended by de.unihalle.informatik.MiToBo.core.datatypes.MTBNeuriteSkelGraph

public class MTBNeuriteSkelGraph
extends MTBGraph

 The class implements a neurite skeleton graph (NSG), based on the skeleton
 of a neurite region. The NSG is directed, in the way that exact one START
 node (mostly the point near the neuron cell body area) exists, which can
 have one or more output edges and no input edges. By the way, there are some
 other nodes from type BRANCH or END inside the graph.
 
 BRANCH nodes: have one input edge and two or more out edges
 END nodes: have exact one input edge and no output edges 
 
 The NSG is build by skeleton traversing, beginning at one
 given node. The direction is implicit corrected, so that at every time there
 is a direct "flow" from the START node to all END nodes. So the START node is
 connected with every END node via exact one path.
 
 If the START nodes is changed, the directness of the graph is automatically
 corrected, and the old node becomes automatically a BRANCH or a END node.
 
 The edges hold the pixels of the skeleton between the nodes.
 It is possible to get all paths from the START node to all END nodes,
 get the longest path in the whole graph, and several other operations,
 needed for a NSG.
 
 The graph is always free of circles. If an circle exists in the underlying
 skeleton, the circle is disconnected in two paths
 (due to the approach of building the graph).
 
 

Author:
Danny Misiak
See Also:
MTBGraph, MTBGraphEdge, MTBNeuriteSkelGraphNode

Field Summary
private  int background_color
           
private  int color_graphEdge
          Color of graph edge points.
private  int color_graphNode
          Color of graph node points.
private  int color_skelBranch
          Color of pre-detected branch points.
private  int color_skelSpecial
          Color of pre-detected special points, for example a 2x2 skeleton region.
private  int color_skelVisitB
          Color of visited graph branch points.
private  int color_skelVisitE
          Color of visited graph edge points.
private  int[][] delta
          X- and Y-coordinate differences of the 8-way neighbors.
private  int height
          Skeleton image size in y-direction.
private  int maxSpineLength
           
private  int regionID
          Region ID of the corresponding neurite region to this neurite skeleton graph.
private  int skeleton_color
          The color of the skeleton in the binary image.
private  int width
          Skeleton image size in x-direction.
 
Fields inherited from class de.unihalle.informatik.MiToBo.core.datatypes.MTBGraph
directed, edges, nodes, numberOfEdges, numberOfNodes
 
Constructor Summary
MTBNeuriteSkelGraph()
          Standard constructor.
MTBNeuriteSkelGraph(int _maxSpineLength)
          Constructor that creates an empty directed MTBNeuriteSkelGraph with defined maximum spine length.
MTBNeuriteSkelGraph(java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> skelNodes, java.util.Vector<MTBGraphEdge> skelEdges, int _maxSpineLength, int _width, int _heigth)
          Constructor to create an directed MTBNeuriteSkelGraph with the given MTBSkeletonGraphNodes and MTBGraphEdges.
 
Method Summary
private  boolean build(int xx, int yy, MTBImageByte skelImg, MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> parentNode)
          Internal method to create the graph from the skeleton image.
 boolean buildSkeletonGraph(int x, int y, int w, int h, MTBImageByte skeletonImg, int skelColor)
           Build the skeleton graph from a given binary skeleton image and a given starting point to build up the graph.
 MTBNeuriteSkelGraph clone()
           
private  void correctDirectness(MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> rootNode)
          Method to correct the direction of every edge inside the skeleton graph from a given root node.
private  void depthFirstSearch(java.util.Vector<java.awt.geom.Point2D.Double> pixels, java.util.Vector<java.lang.Integer> parents, MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> startNode, int label)
          Depth-first-search to collect data from the neurite skeleton graph in a SWC file like format.
 java.util.Vector<java.util.Vector<java.awt.geom.Point2D.Double>> getAllPaths(boolean includeSpines)
          Get the pixels of all paths of the neurite skeleton graph.
 void getAllPixels(java.util.Vector<java.awt.geom.Point2D.Double> pixels)
           Get all pixels of the neurite skeleton graph from the nodes and edges.
private  void getAllPixels(java.util.Vector<java.awt.geom.Point2D.Double> pixels, MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> tmpNode)
           Get all pixels of the neurite skeleton graph from the nodes and edges.
 java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> getBranchNodes()
          Get all branch nodes of the MTBNeuriteSkelGraph.
 java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> getEndNodes()
          Get all end nodes of the MTBNeuriteSkelGraph.
 int getHeight()
          Get skeleton graph image size in y direction.
 java.util.Vector<java.awt.geom.Point2D.Double> getLongestPath(boolean includeSpines)
          Get the pixels of the longest path of the neurite skeleton graph.
private  void getPath(java.util.Vector<java.awt.geom.Point2D.Double> p, MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> n)
          Internal method to traverse the path and return the pixel list.
 int getRegionID()
          Get the region id.
 java.util.Vector<java.awt.geom.Point2D.Double> getShortestPath(boolean includeSpines)
          Get the pixels of the shortest path of the neurite skeleton graph.
 java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> getSkeletonGraphNodes()
          Get all nodes of the MTBNeuriteSkelGraph as MTBNeuriteSkelGraphNodes.
 java.util.Vector<java.util.Vector<java.awt.geom.Point2D.Double>> getSpinePaths()
          Get the pixels of all spine paths of the neurite skeleton graph.
 MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> getStartNode()
          Get the start node of the MTBNeuriteSkelGraph.
 int getWidth()
          Get skeleton graph image size in x direction.
private  MTBImageByte markBranchPoints(MTBImageByte skelImg)
          Mark branch/special points as first step before building up the whole skeleton graph.
 void print()
          Print the neurite skeleton graph informations.
 void setRegionID(int id)
          Set the region id.
 void setStartNode(MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> node)
          Set a new start node.
 MTBImageByte toByteImage()
          Draw the skeleton graph into a binary image.
 MTBImageRGB toImage()
          Visualize the skeleton graph as RGB image.
 MTBImageRGB toImage(MTBImageRGB rgbImage)
          Draw the skeleton graph in the given RGB image.
 void toSWC(java.lang.String fileName, MTBImageByte neuronImage)
          Method to save neurite skeleton graph as SWC file.
 
Methods inherited from class de.unihalle.informatik.MiToBo.core.datatypes.MTBGraph
addEdge, addNode, getEdgeNum, getEdges, getGraphCost, getNodeNum, getNodes, isDirected, removeEdge, removeNode
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

background_color

private int background_color

color_graphEdge

private final int color_graphEdge
Color of graph edge points.

See Also:
Constant Field Values

color_graphNode

private final int color_graphNode
Color of graph node points.

See Also:
Constant Field Values

color_skelBranch

private final int color_skelBranch
Color of pre-detected branch points.

See Also:
Constant Field Values

color_skelSpecial

private final int color_skelSpecial
Color of pre-detected special points, for example a 2x2 skeleton region.

See Also:
Constant Field Values

color_skelVisitB

private final int color_skelVisitB
Color of visited graph branch points.

See Also:
Constant Field Values

color_skelVisitE

private final int color_skelVisitE
Color of visited graph edge points.

See Also:
Constant Field Values

delta

private final int[][] delta
X- and Y-coordinate differences of the 8-way neighbors.


height

private int height
Skeleton image size in y-direction.


maxSpineLength

private int maxSpineLength

regionID

private int regionID
Region ID of the corresponding neurite region to this neurite skeleton graph.


skeleton_color

private int skeleton_color
The color of the skeleton in the binary image. The background is set to the opposite color, for example the skeleton is 0, then the background is set to 255 and vice versa.


width

private int width
Skeleton image size in x-direction.

Constructor Detail

MTBNeuriteSkelGraph

public MTBNeuriteSkelGraph()
Standard constructor. Creates an empty directed MTBNeuriteSkelGraph. Maximum spine length is set to 0.


MTBNeuriteSkelGraph

public MTBNeuriteSkelGraph(int _maxSpineLength)
Constructor that creates an empty directed MTBNeuriteSkelGraph with defined maximum spine length.

Parameters:
_maxSpineLength -

MTBNeuriteSkelGraph

public MTBNeuriteSkelGraph(java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> skelNodes,
                           java.util.Vector<MTBGraphEdge> skelEdges,
                           int _maxSpineLength,
                           int _width,
                           int _heigth)
                    throws MTBNeuriteSkelGraphException
Constructor to create an directed MTBNeuriteSkelGraph with the given MTBSkeletonGraphNodes and MTBGraphEdges.

Parameters:
skelNodes - vector of MTBNeuriteSkelGraphNodes
skelEdges - vector of MTBGraphEdges
Throws:
MTBNeuriteSkelGraphException
Method Detail

build

private boolean build(int xx,
                      int yy,
                      MTBImageByte skelImg,
                      MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> parentNode)
Internal method to create the graph from the skeleton image. Does the actual work to build up the neurite skeleton graph.

Parameters:
xx - point coordinate in x-direction
yy - point coordinate in y-direction
skelImg - the binary skeleton image
parentNode - parent node of the current point
Returns:
true if graph was successfully build

buildSkeletonGraph

public boolean buildSkeletonGraph(int x,
                                  int y,
                                  int w,
                                  int h,
                                  MTBImageByte skeletonImg,
                                  int skelColor)
 Build the skeleton graph from a given binary skeleton image and a given
 starting point to build up the graph.
 
 
 Build definition:
 
 The graph is build from a given starting point (mostly a end point of the
 skeleton, near the neuron cell body). All other points are marked
 automatically by building up the graph.
 Branch points are marked as BRANCH nodes, end points are marked as END
 nodes and edge points are added to the edge data structure.
 
 BRANCH nodes: have one input edge and two or more out edges
 END nodes: have exact one input edge and no output edges 
 
 By building up the graph, 4-way neighbors are visited first, diagonal
 neighbors are visited in the second step.
 
 The graph is always free of circles. If an circle exists in the underlying
 skeleton, the circle is disconnected in two paths
 (due to the approach of building the graph).
 
 

Parameters:
x - starting point coordinate in x-direction
y - starting point coordinate in y-direction
w - width of the skeleton image
h - height of the skeleton image
skeletonImg - the binary skeleton image
skelColor - color of the skeleton, the background is set to the opposite color, for example the skeleton is 0, then the background is set to 255 and vice versa
Returns:
true if graph was successfully build

clone

public MTBNeuriteSkelGraph clone()
Overrides:
clone in class java.lang.Object

correctDirectness

private void correctDirectness(MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> rootNode)
Method to correct the direction of every edge inside the skeleton graph from a given root node. The graph is directed like a tree. One root node and several branch and end nodes. Every end node can be visit via one directed path from the start (root) node.


depthFirstSearch

private void depthFirstSearch(java.util.Vector<java.awt.geom.Point2D.Double> pixels,
                              java.util.Vector<java.lang.Integer> parents,
                              MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> startNode,
                              int label)
Depth-first-search to collect data from the neurite skeleton graph in a SWC file like format.

Parameters:
pixels - empty vector where skeleton pixels will be stored
parents - empty vector where parents of each skeleton pixels will be stored
startNode - start node for traversing graph and collect data
label - label for parent of start node (root)

getAllPaths

public java.util.Vector<java.util.Vector<java.awt.geom.Point2D.Double>> getAllPaths(boolean includeSpines)
Get the pixels of all paths of the neurite skeleton graph. The pixels are ordered from the START node to the corresponding END node of the path.

Parameters:
includeSpines -
Returns:
Vector of all paths.

getAllPixels

public void getAllPixels(java.util.Vector<java.awt.geom.Point2D.Double> pixels)
 
 Get all pixels of the neurite skeleton graph from the nodes and edges.
 Pixel collection starts at the start node of the skeleton graph.
 
 WARNING!!!
 The specific order within the list depends on the edge direction between
 the single nodes. Order of the single edges depends on the build process.
 
 

Parameters:
pixels - empty list to be filled

getAllPixels

private void getAllPixels(java.util.Vector<java.awt.geom.Point2D.Double> pixels,
                          MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> tmpNode)
 
 Get all pixels of the neurite skeleton graph from the nodes and edges.
 
 WARNING!!!
 The specific order within the list depends on the edges and their direction
 between the single nodes.
 Order of the single edges depends on the build process.
 
 

Parameters:
pixels - empty list to be filled
tmpNode - current node for pixel collection

getBranchNodes

public java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> getBranchNodes()
Get all branch nodes of the MTBNeuriteSkelGraph.

Returns:
Vector of MTBNeuriteSkelGraphNode of type BRANCH.

getEndNodes

public java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> getEndNodes()
Get all end nodes of the MTBNeuriteSkelGraph.

Returns:
Vector of MTBNeuriteSkelGraphNode of type END.

getHeight

public int getHeight()
Get skeleton graph image size in y direction.


getLongestPath

public java.util.Vector<java.awt.geom.Point2D.Double> getLongestPath(boolean includeSpines)
Get the pixels of the longest path of the neurite skeleton graph. The pixels are ordered from the START node to the corresponding END node of the path.

Parameters:
includeSpines -
Returns:
Pixel of longest path.

getPath

private void getPath(java.util.Vector<java.awt.geom.Point2D.Double> p,
                     MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> n)
Internal method to traverse the path and return the pixel list.


getRegionID

public int getRegionID()
Get the region id. This id indirectly links the neurite skeleton graph to a neurite region, where the skeleton is created from. So in another application the skeleton can be linked to a region and vice versa.


getShortestPath

public java.util.Vector<java.awt.geom.Point2D.Double> getShortestPath(boolean includeSpines)
Get the pixels of the shortest path of the neurite skeleton graph. The pixels are ordered from the START node to the corresponding END node of the path.

Parameters:
includeSpines -
Returns:
Pixel of shortest path.

getSkeletonGraphNodes

public java.util.Vector<MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double>> getSkeletonGraphNodes()
Get all nodes of the MTBNeuriteSkelGraph as MTBNeuriteSkelGraphNodes.

Returns:
Vector of MTBNeuriteSkelGraphNode.

getSpinePaths

public java.util.Vector<java.util.Vector<java.awt.geom.Point2D.Double>> getSpinePaths()
Get the pixels of all spine paths of the neurite skeleton graph. The pixels are ordered from the START node to the corresponding END node of the path.

Returns:
Vector of spine paths.

getStartNode

public MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> getStartNode()
Get the start node of the MTBNeuriteSkelGraph.

Returns:
MTBNeuriteSkelGraphNode of type START.

getWidth

public int getWidth()
Get skeleton graph image size in x direction.


markBranchPoints

private MTBImageByte markBranchPoints(MTBImageByte skelImg)
Mark branch/special points as first step before building up the whole skeleton graph.

Parameters:
skelImg - binary skeleton image
Returns:
Skeleton image with labeled branch/special points.

print

public void print()
Print the neurite skeleton graph informations.

Overrides:
print in class MTBGraph

setRegionID

public void setRegionID(int id)
Set the region id. This id indirectly links the neurite skeleton graph to a neurite region, where the skeleton is created from. So in another application the skeleton can be linked to a region and vice versa.


setStartNode

public void setStartNode(MTBNeuriteSkelGraphNode<java.awt.geom.Point2D.Double> node)
Set a new start node. For the skeleton graph only one start node can exist! The node type for the old start node automatically becomes a node of type BRANCH or END, depending on the number of output edges. If no output edges exist, the nodes becomes a END node, if some output edges exit, the node becomes a BRANCH node. Direction correction of the edges is automatically applied too.

Parameters:
node - new start node

toByteImage

public MTBImageByte toByteImage()
Draw the skeleton graph into a binary image. Background is filled with white, graph is drawn in black.


toImage

public MTBImageRGB toImage()
Visualize the skeleton graph as RGB image. Edge points colored in bright green, END nodes colored in red, BRANCH nodes colored in blue and START nodes colored in green.

Returns:
RGB labeled graph image.

toImage

public MTBImageRGB toImage(MTBImageRGB rgbImage)
Draw the skeleton graph in the given RGB image. Edge points colored in bright green, END nodes colored in red, BRANCH nodes colored in blue and START nodes colored in green.

Returns:
Graph drawn in the given RGB image.

toSWC

public void toSWC(java.lang.String fileName,
                  MTBImageByte neuronImage)
Method to save neurite skeleton graph as SWC file.

Parameters:
fileName - filename for saving the SWC file
neuronImage - if radii for each skeleton point should be calculated, a image must be given to calculate the distance map of the neuron region and get radius of each skeleton point, can be null