@ALDAOperator(genericExecutionMode=ALL, level=APPLICATION) public class DistanceTransform extends MTBOperator
Class to calculate a distance map / field from a binary image using the Champfer algorithm from G. Borgefors, "Distance transformations in digital images", Computer Vision, Graphics, and Image Processing, vol. 34, pp. 344–371, 1986. Several distance metrics (Euclide, Chessboard, Cityblock) and the foreground (0 for black and 1 for white) can be specified. A 8-way neighborhood is used. NOTE! The distance is calculated for each background pixel to the nearest foreground pixel. For example, if the distance should be calculated inside a white object, the black background should be set as foreground color. The distance field is created as MTBImage or as a two dimensional double array. First dimension specifies the y-coordinate of the field, and the second dimension specifies the x-coordinate of the field.Optionally this class offers as additional information a map of the precursor pixels for each position, i.e. the pixel which lead to the actual distance value, and a map containing for each background pixel the object pixel being closest to the pixel according to the distances calculated during the transformation.
Note that if precursor information is extracted the distance transform runs slightly less efficient than the original one since the two additional maps are filled during the calculations and more memory is required for them.
Modifier and Type | Class and Description |
---|---|
static class |
DistanceTransform.DistanceMetric
Several distance metrics.
|
static class |
DistanceTransform.ForegroundColor
Color of binary image foreground.
|
Modifier and Type | Field and Description |
---|---|
private Point2D.Double[][] |
closestObjectPixelMap
Map of closest object pixels for each background location.
|
private MTBImage |
distanceImg
The distance field as MTBImage.
|
private double[][] |
distanceMap
The distance field as two-dimensional double array.
|
private DistanceTransform.DistanceMetric |
distanceMetric
Distance metric to apply.
|
private boolean |
extractPrecursorInfos
Flag to enable/disable extraction of precursor infos.
|
private DistanceTransform.ForegroundColor |
foreground
Foreground color of the foreground object.
|
private int |
height
Height of the given image.
|
private MTBImageByte |
inputImage
Binary input image.
|
private Point2D.Double[][] |
precursorMap
Map of precursor positions for each pixel in the background.
|
private int |
width
Width of the given image.
|
Constructor and Description |
---|
DistanceTransform()
Standard constructor.
|
DistanceTransform(MTBImageByte image,
DistanceTransform.DistanceMetric dm,
DistanceTransform.ForegroundColor fg)
Constructor to create a new DistanceTransform object.
|
Modifier and Type | Method and Description |
---|---|
private void |
calcDM()
Method to calculate the distance map of the given binary image
using the Chamfer-algorithm.
|
Point2D.Double[][] |
getClosestObjectPixelMap()
Get the calculated map of closest object pixels.
|
MTBImage |
getDistanceImage()
Get the calculated distance map image.
|
double[][] |
getDistanceMap()
Get the calculated distance map.
|
DistanceTransform.DistanceMetric |
getDistMetric()
Get the used distance metric.
|
DistanceTransform.ForegroundColor |
getForeground()
Get the used foreground color.
|
int |
getHeight()
Get image height.
|
MTBImageByte |
getInImg()
Get the input image.
|
Point2D.Double[][] |
getPrecursorMap()
Get the calculated precursor map.
|
int |
getWidth()
Get image width.
|
protected void |
operate() |
void |
setDistMetric(DistanceTransform.DistanceMetric metric)
Set the distance metric.
|
void |
setForeground(DistanceTransform.ForegroundColor fColor)
Set the foreground color.
|
void |
setInImg(MTBImageByte inImg)
Set the input image.
|
void |
setPrecursorInfosEnabled(boolean f)
Enable or disable extraction of additional precursor infos.
|
readResolve
addOperatorExecutionProgressEventListener, addParameter, addParameter, addParameterUnconditioned, fieldContained, fireOperatorExecutionProgressEvent, getALDPortHashAccessKey, getConstructionMode, getDocumentation, getHidingMode, getInactiveParameterNames, getInInoutNames, getInInoutNames, getInNames, getInOutNames, getMissingRequiredInputs, getName, getNumParameters, getOutInoutNames, getOutNames, getParameter, getParameterDescriptor, getParameterDescriptorUnconditioned, getParameterNames, getParameterUnconditioned, getSupplementalNames, getVerbose, getVersion, handleOperatorExecutionProgressEvent, hasInOutParameters, hasParameter, isAnnotatedParameter, isConfigured, print, print, print, printInterface, printInterface, readHistory, reinitializeParameterDescriptors, removeOperatorExecutionProgressEventListener, removeParameter, runOp, runOp, runOp, setConstructionMode, setConstructionMode, setConstructionMode, setHidingMode, setName, setParameter, setParameterUnconditioned, setVerbose, toStringVerbose, unconfiguredItems, validate, validateCustom, validateGeneric, writeHistory, writeHistory, writeHistory
@Parameter(label="Binary Input Image", required=true, direction=IN, description="Binary input image.", mode=STANDARD, dataIOOrder=0) private transient MTBImageByte inputImage
@Parameter(label="Distance Metric", required=true, direction=IN, description="Used distance metric", mode=STANDARD, dataIOOrder=1) private DistanceTransform.DistanceMetric distanceMetric
@Parameter(label="Foreground Color", required=true, direction=IN, description="Color of foreground.", mode=STANDARD, dataIOOrder=2) private DistanceTransform.ForegroundColor foreground
@Parameter(label="Extract Precursor Iinformation?", required=true, direction=IN, description="Flag for precursor infos.", mode=STANDARD, dataIOOrder=3) private boolean extractPrecursorInfos
@Parameter(label="Distance Map Image", direction=OUT, description="Image of the distance map.") private transient MTBImage distanceImg
@Parameter(label="Distance Map", direction=OUT, description="2D distance map array.") private double[][] distanceMap
@Parameter(label="Precursor Map", direction=OUT, description="2D map of precursor pixels for each position.") private Point2D.Double[][] precursorMap
@Parameter(label="Closest Object Pixel Map", direction=OUT, description="Map of closest object pixels for each position.") private Point2D.Double[][] closestObjectPixelMap
private int width
private int height
public DistanceTransform() throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
- Thrown in case of failure.public DistanceTransform(MTBImageByte image, DistanceTransform.DistanceMetric dm, DistanceTransform.ForegroundColor fg) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
image
- the input image to calculate the distance map on itdm
- the distance metricfg
- set foreground white or blackde.unihalle.informatik.Alida.exceptions.ALDOperatorException
- Thrown in case of failure.public MTBImageByte getInImg()
public void setInImg(MTBImageByte inImg)
inImg
- Input image.public DistanceTransform.DistanceMetric getDistMetric()
public void setDistMetric(DistanceTransform.DistanceMetric metric)
metric
- Distance metric to apply.public DistanceTransform.ForegroundColor getForeground()
public void setForeground(DistanceTransform.ForegroundColor fColor)
fColor
- Foreground color.public void setPrecursorInfosEnabled(boolean f)
f
- If true, additional infos are extracted.public MTBImage getDistanceImage()
public double[][] getDistanceMap()
First dimension specifies the y-coordinate of the field, and the second dimension specifies the x-coordinate.
public Point2D.Double[][] getPrecursorMap()
First dimension specifies the y-coordinate of the field, and the second dimension specifies the x-coordinate.
public Point2D.Double[][] getClosestObjectPixelMap()
First dimension specifies the y-coordinate of the field, and the second dimension specifies the x-coordinate.
public int getWidth()
public int getHeight()
protected void operate()
operate
in class de.unihalle.informatik.Alida.operator.ALDOperator
private void calcDM()
A specified distance metric and the fore- and background of the binary image can be chosen. A neighborhood of 8 is used for the distance calculations.
Copyright © 2010–2020 Martin Luther University Halle-Wittenberg, Institute of Computer Science, Pattern Recognition and Bioinformatics. All rights reserved.