io.loader.load2D
Class SkeletonParser2D

java.lang.Object
  extended by io.loader.shared.SkeletonParser
      extended by io.loader.load2D.SkeletonParser2D

public class SkeletonParser2D
extends SkeletonParser

Given the path to a binary image containing the skeleton, and the path to a binary image containing the object's shape, SkeletonParser2D creates a SkeletonObject from this given input data.

Tested input image types are by now .png and .gif. Example usage:

 
 SkeletonParser parser = new SkeletonParser ("/path/to/skeleton.png", "/path/to/object.png");
 SkeletonObject object = parser.getSkeleton();
 
 
Warning: The assumption is we have unit pixels here.


Field Summary
private  java.util.List<java.awt.Point> allContourPoints
          list containing all contour points (outer contours as well as inner contours
private  org.apache.log4j.Logger logger
          logger instance
private  java.lang.String objectfilename
          the path to the image containing the object shape
private  ij.ImagePlus objectImage
          image containing the object shape
private  ij.io.Opener opener
          imagej opener instance, offers more possibilites than ImageIO
private  java.lang.String skeletonfilename
          the path to the image containing the skeleton
private  ij.ImagePlus skeletonImage
          image containing the skeleton
 
Fields inherited from class io.loader.shared.SkeletonParser
allEndnodes, allJunctionNodes, config, skeletonObject
 
Constructor Summary
SkeletonParser2D(java.lang.String skeletonfilename, java.lang.String objectfilename)
          Constructor.
SkeletonParser2D(java.lang.String skeletonfilename, java.lang.String objectfilename, boolean flipped)
           
SkeletonParser2D(java.lang.String skeletonfilename, java.lang.String objectfilename, Config config)
           
SkeletonParser2D(java.lang.String skeletonfilename, java.lang.String objectfilename, Config config, boolean flipped)
          Constructor.
 
Method Summary
private  SkeletonNode checkNeighborHood(java.awt.Point cp)
          check if a skeleton end node is in the 3x3 neighbor hood of the specified contour point.
private  void cleanJunctionNodes(java.util.List<SkeletonNode> junctionnodes)
          In some constellations, directly adjacent nodes are recognized as junction nodes.
private  void getContour()
          set the object's inner and outer contours.
protected  void getCriticalNodes()
          extract all critical nodes, that is, end nodes and junction nodes
protected  void getDistanceTransform()
          compute and set the shape's distance transform
private  boolean isNeighborOf(java.awt.Point cp, SkeletonNode n)
          check if the specified skeleton node is in the 3x3 neighborhood of the specified contour point.
private  boolean isSkeleton(int argb)
          check if the specified color code is encoding a skeleton node
private  void load(java.lang.String skeletonfilename, java.lang.String objectfilename, boolean flipped)
          load the skeleton image and shape image, specified by the parameters.
private  void loadObjectImage(boolean flipped)
          load the object image
private  void loadSkeletonImage(boolean flipped)
          load the skeleton image
private  void prepareImage(ij.ImagePlus objectImage)
          Prepare the image to make sure some conditions are fullfilled: all pixel values are 0 or 255 tell imagej that this is a binary image invert the image in case the foreground seems to be black, the background seems to be white (by now, this is estimated on the pixel in the upper left corner)
protected  java.util.Map<SkeletonNode,java.util.List<SkeletonBranch>> sampleParts()
          sample all SkeletonBranches emanating from each critical node.
private  void setAllContourPoints()
          extract all contour points from the object's contour and save them to a list.
private  void setSize()
          set skeleton object's width and height, based on the input image's size.
private  void sortEndPoints()
          sort a list of end nodes by traversing an object's contour in clockwise direction and checking for each contour point if there is a skeleton node in the 3x3 neighborhood.
 
Methods inherited from class io.loader.shared.SkeletonParser
deleteUnconnectedComponents, deleteUnnecessaryBranches, extractPaths, getSkeleton, parse, preprocessGraph
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allContourPoints

private java.util.List<java.awt.Point> allContourPoints
list containing all contour points (outer contours as well as inner contours


logger

private final org.apache.log4j.Logger logger
logger instance


objectfilename

private java.lang.String objectfilename
the path to the image containing the object shape


objectImage

private ij.ImagePlus objectImage
image containing the object shape


opener

private final ij.io.Opener opener
imagej opener instance, offers more possibilites than ImageIO


skeletonfilename

private java.lang.String skeletonfilename
the path to the image containing the skeleton


skeletonImage

private ij.ImagePlus skeletonImage
image containing the skeleton

Constructor Detail

SkeletonParser2D

public SkeletonParser2D(java.lang.String skeletonfilename,
                        java.lang.String objectfilename)
                 throws java.io.IOException,
                        InvalidConfigParameterException
Constructor. Create a new SkeletonParser instance, defined by the path to the shape image and the path to the skeleton image.

Both images should be binary images, with black background and white foreground.

Parameters:
skeletonfilename - the path to the binary image containing the skeleton
objectfilename - the path to the binary image containing the object.
Throws:
java.io.IOException - if one of the images was not found.
InvalidConfigParameterException

SkeletonParser2D

public SkeletonParser2D(java.lang.String skeletonfilename,
                        java.lang.String objectfilename,
                        boolean flipped)
                 throws java.io.IOException,
                        InvalidConfigParameterException
Throws:
java.io.IOException
InvalidConfigParameterException

SkeletonParser2D

public SkeletonParser2D(java.lang.String skeletonfilename,
                        java.lang.String objectfilename,
                        Config config)
                 throws java.io.IOException,
                        InvalidConfigParameterException
Throws:
java.io.IOException
InvalidConfigParameterException

SkeletonParser2D

public SkeletonParser2D(java.lang.String skeletonfilename,
                        java.lang.String objectfilename,
                        Config config,
                        boolean flipped)
                 throws java.io.IOException
Constructor. Create a new SkeletonParser instance, defined by the path to the shape image and the path to the skeleton image. If the third argument, flipped, is set to true, both the shape image and the skeleton image will be flipped horizontally before they are parsed.

Parameters:
skeletonfilename - - the path to the binary image containing the skeleton
objectfilename - - the path to the binary image containing the object.
flipped - - if true, both images will be flipped horizontally before the skeleton is parsed
Throws:
java.io.IOException - - if one if the images could not be found
Method Detail

load

private void load(java.lang.String skeletonfilename,
                  java.lang.String objectfilename,
                  boolean flipped)
           throws java.io.IOException
load the skeleton image and shape image, specified by the parameters. also set site and contour automatically

Parameters:
skeletonfilename - - path to skeleton image
objectfilename - - path to object image
flipped - - true if the image has to be flipped, false if not
Throws:
java.io.IOException - - if one of the files could not be found

checkNeighborHood

private SkeletonNode checkNeighborHood(java.awt.Point cp)
check if a skeleton end node is in the 3x3 neighbor hood of the specified contour point.

Parameters:
cp - the contour point whose neighborhood will be search for skeleton points
Returns:
the endpoint in the contour point's 3x3 neighborhood, null if there is none

getContour

private void getContour()
set the object's inner and outer contours.


getDistanceTransform

protected void getDistanceTransform()
Description copied from class: SkeletonParser
compute and set the shape's distance transform

Specified by:
getDistanceTransform in class SkeletonParser

sampleParts

protected java.util.Map<SkeletonNode,java.util.List<SkeletonBranch>> sampleParts()
                                                                          throws InvalidSkeletonException
Description copied from class: SkeletonParser
sample all SkeletonBranches emanating from each critical node. For each critical node, a list of all emanating parts is stored. The key in the map is the critical node, the value is the list of all skeleton branches emanating from the node that is the key.

Specified by:
sampleParts in class SkeletonParser
Returns:
a map containing all skeleton branches. The key in the return map is a critical node, the value in the map is a list of all skeleton branches emanating from the node key.
Throws:
InvalidSkeletonException

getCriticalNodes

protected void getCriticalNodes()
                         throws InvalidSkeletonException
Description copied from class: SkeletonParser
extract all critical nodes, that is, end nodes and junction nodes

Specified by:
getCriticalNodes in class SkeletonParser
Throws:
InvalidSkeletonException

cleanJunctionNodes

private void cleanJunctionNodes(java.util.List<SkeletonNode> junctionnodes)
                         throws InvalidSkeletonException
In some constellations, directly adjacent nodes are recognized as junction nodes. This is information we have no use for. Thus, we now have to clean up this mess by selecting one junction node for each of these " NodeArea"s

Parameters:
junctionnodes - - list of all found junction nodes (that is, nodes with more than two neighbors)
Throws:
InvalidSkeletonException - - if the skeleton seems to be broken

isNeighborOf

private boolean isNeighborOf(java.awt.Point cp,
                             SkeletonNode n)
check if the specified skeleton node is in the 3x3 neighborhood of the specified contour point.

Parameters:
cp - the contour point
n - the skeleton node
Returns:
true if the skeleton node is in the 3x3 neighborhood of the skeleton, false if not

isSkeleton

private boolean isSkeleton(int argb)
check if the specified color code is encoding a skeleton node

Parameters:
argb -
Returns:
true if the specified color value is the skeleton color, false otherwise

loadObjectImage

private void loadObjectImage(boolean flipped)
                      throws java.io.IOException
load the object image

Parameters:
flipped -
Throws:
java.io.IOException - if the image was not found

prepareImage

private void prepareImage(ij.ImagePlus objectImage)
Prepare the image to make sure some conditions are fullfilled:

Parameters:
objectImage - the image to be prepared

loadSkeletonImage

private void loadSkeletonImage(boolean flipped)
                        throws java.io.IOException
load the skeleton image

Parameters:
flipped - true if the image shall be flipped horizontally, false if not
Throws:
java.io.IOException - if the image was not found

setAllContourPoints

private void setAllContourPoints()
extract all contour points from the object's contour and save them to a list.


setSize

private void setSize()
set skeleton object's width and height, based on the input image's size.


sortEndPoints

private void sortEndPoints()
sort a list of end nodes by traversing an object's contour in clockwise direction and checking for each contour point if there is a skeleton node in the 3x3 neighborhood.