de.unihalle.informatik.MiToBo.segmentation.contours.extraction
Class ContourOnLabeledComponents

java.lang.Object
  extended by de.unihalle.informatik.Alida.operator.ALDOperator
      extended by de.unihalle.informatik.MiToBo.core.operator.MTBOperator
          extended by de.unihalle.informatik.MiToBo.segmentation.contours.extraction.ContourOnLabeledComponents
All Implemented Interfaces:
de.unihalle.informatik.Alida.datatypes.ALDConfigurationValidator

@ALDAOperator(genericExecutionMode=NONE,
              level=APPLICATION)
public class ContourOnLabeledComponents
extends MTBOperator

Class to segment contours from a binary image using the contour following algorithm. The contours are only segmented from a set of given image regions in this binary image. If no image regions exist you should use one of the LabelComponent methods from the package de.unihalle.informatik.MiToBo.segmentation.regions.labeling.

Outer contours as well as inner contours (length greater than a given value) are segmented.

Author:
Danny Misiak

Nested Class Summary
static class ContourOnLabeledComponents.ContourType
          The possible type of contours for segmentation.
 
Nested classes/interfaces inherited from class de.unihalle.informatik.Alida.operator.ALDOperator
de.unihalle.informatik.Alida.operator.ALDOperator.HidingMode
 
Field Summary
private  ContourOnLabeledComponents.ContourType contourType
          Special type of contours to calculate.
private  int height
          Image height.
private  int innerContourLengthMin
          Minimum number of pixels a inner contour must have (length of the contour).
private  MTBImageByte inputImage
          The binary input image where the contours should be calculated from.
private  MTBRegion2DSet inputRegions
          The input regions where the contours should be calculated from.
private  MTBContour2DSet resultContours
          * The calculated contours, every contour can include several inner contours.
private  MTBImageByte resultImage
          * The binary image with the calculated contours and the contours as possible outputs from the operator.
private  int width
          Image width.
 
Fields inherited from class de.unihalle.informatik.Alida.operator.ALDOperator
completeDAG, name, portHashAccess, verbose, versionProvider
 
Constructor Summary
ContourOnLabeledComponents()
          Standard constructor.
ContourOnLabeledComponents(MTBImageByte inImg, MTBRegion2DSet inRegions, ContourOnLabeledComponents.ContourType type, int length)
          Constructor.
 
Method Summary
protected  MTBContour2DSet addInnerContours()
          Adding the possible inner contours to the outer contour of a region.
protected  MTBImageByte calcContours()
          Get all inner- and outer-contours for the given regions.
protected  int findNextPoint(java.awt.geom.Point2D.Double Xc, int dir, MTBImageByte theImage)
          Find direction to next pixel in specific direction from the last pixel.
 ContourOnLabeledComponents.ContourType getContourType()
          Get reference to the current contour type.
 int getHeight()
          Get image height.
 int getInnerContourLengthMin()
          Get the minimum number of pixels in the inner contour (length of the contour).
 MTBImageByte getInputImage()
          Get reference to the current input image.
 MTBRegion2DSet getInputRegions()
          Get reference to the input regions.
protected  MTBContour2DSet getOuterContours(MTBRegion2DSet theRegions, MTBImageByte theImage)
          Calculate the outer contours of the given regions in a image.
 MTBContour2DSet getResultContours()
          Get reference to the calculated contours.
 MTBImageByte getResultImage()
          Get reference to the binary image with the calculated contours.
 int getWidth()
          Get image width.
protected  void operate()
          This method does the actual work.
 void setContourType(ContourOnLabeledComponents.ContourType type)
          Set reference to the contour type.
 void setHeight(int h)
          Set image height.
 void setInnerContourLengthMin(int length)
          Set the minimum number of pixels in the inner contour (length of the contour).
 void setInputImage(MTBImageByte inImg)
          Set reference to the current input image.
 void setInputRegions(MTBRegion2DSet inRegions)
          Set reference to the the input regions.
 void setWidth(int w)
          Set image width.
protected  MTBImageByte toMTBImageByte()
          Method to save all contours from the regions on a binary image with specific width and height.
protected  MTBContour2D traceContour(int xS, int yS, MTBImageByte theImage)
          Trace contour, starting at (xS, yS) in direction dS.
 
Methods inherited from class de.unihalle.informatik.MiToBo.core.operator.MTBOperator
readResolve
 
Methods inherited from class de.unihalle.informatik.Alida.operator.ALDOperator
deserializeFromXmlFile, fieldContained, getALDPortHashAccessKey, getConstructionMode, getInInoutNames, getInInoutNames, getInNames, getInOutNames, getMissingRequiredInputs, getName, getNumParameters, getOutInoutNames, getOutNames, getParameter, getParameterDescriptor, getParameterNames, getSupplementalNames, getVerbose, getVersion, isConfigured, parametersToXmlObject, print, print, print, printInterface, printInterface, readHistory, reinitializeParameterDescriptors, runOp, runOp, runOp, serializeToXmlFile, setConstructionMode, setName, setParameter, setParametersFromXml, setParametersFromXml, setVerbose, toStringVerbose, unconfiguredItems, validate, validateCustom, validateGeneric, writeHistory, writeHistory, writeHistory, writeParametersToXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contourType

@Parameter(label="Contour Type",
           required=true,
           direction=IN,
           description="Contour type.")
private ContourOnLabeledComponents.ContourType contourType
Special type of contours to calculate. Type can be inner, outer and both.


height

private transient int height
Image height.


innerContourLengthMin

@Parameter(label="Inner Contour Length Min",
           required=true,
           direction=IN,
           description="Minimum of inner contour length.")
private int innerContourLengthMin
Minimum number of pixels a inner contour must have (length of the contour). No inner contours with length below this value will be segmented.


inputImage

@Parameter(label="Input Image",
           required=true,
           direction=IN,
           description="Input image.")
private transient MTBImageByte inputImage
The binary input image where the contours should be calculated from.


inputRegions

@Parameter(label="Input Regions",
           required=true,
           direction=IN,
           description="Input regions.")
private transient MTBRegion2DSet inputRegions
The input regions where the contours should be calculated from.


resultContours

@Parameter(label="Result Contours",
           required=true,
           direction=OUT,
           description="Resulting contour set.")
private transient MTBContour2DSet resultContours
* The calculated contours, every contour can include several inner contours.


resultImage

@Parameter(label="Result Image",
           required=true,
           direction=OUT,
           description="Result image with contours.")
private transient MTBImageByte resultImage
* The binary image with the calculated contours and the contours as possible outputs from the operator.


width

private transient int width
Image width.

Constructor Detail

ContourOnLabeledComponents

public ContourOnLabeledComponents()
                           throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Standard constructor.

Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

ContourOnLabeledComponents

public ContourOnLabeledComponents(MTBImageByte inImg,
                                  MTBRegion2DSet inRegions,
                                  ContourOnLabeledComponents.ContourType type,
                                  int length)
                           throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Constructor. A new operator object is initialized.

Parameters:
inImg - input image to work on
inRegions - regions to get the contours from
type - type of the resulting contour regions to get the contours from
length - minimum number of pixels that a inner region must have (length ofimport de.unihalle.informatik.MiToBo.core.exceptions.*; the inner contour) to calculate the inner contour
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Method Detail

addInnerContours

protected MTBContour2DSet addInnerContours()
                                    throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                                           de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Adding the possible inner contours to the outer contour of a region.

Returns:
Vector including all inner contours of a outer contour.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

calcContours

protected MTBImageByte calcContours()
                             throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                                    de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Get all inner- and outer-contours for the given regions.

Returns:
Image including all contours that should be segmented.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

findNextPoint

protected int findNextPoint(java.awt.geom.Point2D.Double Xc,
                            int dir,
                            MTBImageByte theImage)
Find direction to next pixel in specific direction from the last pixel.

Parameters:
Xc - starting point
dir - direction of last point
theImage - the binary image to validate if pixel is black or white (get the label)
Returns:
Next direction.

getContourType

public ContourOnLabeledComponents.ContourType getContourType()
Get reference to the current contour type.

Returns:
The used contour type.

getHeight

public int getHeight()
Get image height.


getInnerContourLengthMin

public int getInnerContourLengthMin()
Get the minimum number of pixels in the inner contour (length of the contour). No inner contours with a length below this value will be segmented.

Returns:
Minimum value of pixels for a inner region.

getInputImage

public MTBImageByte getInputImage()
Get reference to the current input image.

Returns:
Input image to work on.

getInputRegions

public MTBRegion2DSet getInputRegions()
Get reference to the input regions.

Returns:
Region2D vector including all regions.

getOuterContours

protected MTBContour2DSet getOuterContours(MTBRegion2DSet theRegions,
                                           MTBImageByte theImage)
Calculate the outer contours of the given regions in a image. Method from the book: W. Burger, M.J. Burge, "Digitale Bildverarbeitung. Eine Einfuehrung mit Java und ImageJ.", page 211

Parameters:
theRegions - Regions to get contours from.
theImage - Binary image of the regions to get the contours from.
Returns:
Vector of contours from the given regions.

getResultContours

public MTBContour2DSet getResultContours()
Get reference to the calculated contours.

Returns:
Inner- and outer-contours of the regions.

getResultImage

public MTBImageByte getResultImage()
Get reference to the binary image with the calculated contours.

Returns:
Binary image with contours

getWidth

public int getWidth()
Get image width.


operate

protected void operate()
                throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                       de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
This method does the actual work.

Specified by:
operate in class de.unihalle.informatik.Alida.operator.ALDOperator
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

setContourType

public void setContourType(ContourOnLabeledComponents.ContourType type)
Set reference to the contour type.


setHeight

public void setHeight(int h)
Set image height.


setInnerContourLengthMin

public void setInnerContourLengthMin(int length)
Set the minimum number of pixels in the inner contour (length of the contour). No inner contours with a length below this value will be segmented.


setInputImage

public void setInputImage(MTBImageByte inImg)
Set reference to the current input image.


setInputRegions

public void setInputRegions(MTBRegion2DSet inRegions)
Set reference to the the input regions.


setWidth

public void setWidth(int w)
Set image width.


toMTBImageByte

protected MTBImageByte toMTBImageByte()
Method to save all contours from the regions on a binary image with specific width and height.

Returns:
2D inner- and outer-contours in a binary image of type MTBImageByte.

traceContour

protected MTBContour2D traceContour(int xS,
                                    int yS,
                                    MTBImageByte theImage)
Trace contour, starting at (xS, yS) in direction dS.

Parameters:
xS - starting x-coordinate
yS - starting y-coordinate
theImage - the binary image to validate if pixel is black or white (get the label)
Returns:
Contour of the region.