CVB.Net 14.0
NonLinearTransformation Class Reference

Object implementing the non linear polynomially approximated transform implemented in the CVB Foundation Package. More...

Inherits INativeHandle.

Public Member Functions

delegate bool CreationProgress (int stepsTotal, int stepsDone)
 Delegate type of the progress callbacks that can be passed to some constructors of NonLinearTransformation for progress reporting. More...
 
void Dispose ()
 Dispose method that releases the classifier
 
 NonLinearTransformation (string fileName)
 Load a saved transformation from a file. More...
 
void Save (string fileName)
 Write the transformation to a file. More...
 
Image Transform (Image img, Size2D targetSize, Point2D targetOffset)
 Transform an image with this nonlinear transformation. More...
 
Point2Dd[] Transform (ICollection< IPosition > points)
 Transform a sequence of points with this nonlinear transformation. More...
 
Point2Dd Transform (IPosition pt)
 Transform a point with this nonlinear transformation. More...
 
RectD Transform (RectD rect)
 Transform a rect with this nonlinear transformation. More...
 
Image InverseTransform (Image img, Size2D targetSize, Point2D targetOffset)
 Back-transform an image with this nonlinear transformation. More...
 
Point2Dd[] InverseTransform (ICollection< IPosition > points)
 Back transform a sequence of points with this nonlinear transformation. More...
 
Point2Dd InverseTransform (IPosition pt)
 Back-Transform a point with this nonlinear transformation. More...
 

Static Public Member Functions

static NonLinearTransformation FromCalibrationPattern (ImagePlane plane, CalibrationPatternStyle style, CalibrationPatternContrast contrast, int gridSpacing, int minContrast, double maxRatio, int order, out double quality)
 Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object. More...
 
static NonLinearTransformation FromCalibrationPattern (ImagePlane plane, Area2D aoi, CalibrationPatternStyle style, CalibrationPatternContrast contrast, int gridSpacing, int minContrast, double maxRatio, int order, out double quality)
 Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object. More...
 
static NonLinearTransformation FromCalibrationPattern (ImagePlane plane, CalibrationPatternStyle style, CalibrationPatternContrast contrast, int gridSpacing, int minContrast, double maxRatio, int order, CreationProgress progressDelegate, out double quality)
 Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object. More...
 
static NonLinearTransformation FromCalibrationPattern (ImagePlane plane, Area2D aoi, CalibrationPatternStyle style, CalibrationPatternContrast contrast, int gridSpacing, int minContrast, double maxRatio, int order, CreationProgress progressDelegate, out double quality)
 Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object. More...
 
static NonLinearTransformation FromPositionLists< T > (ICollection< T > originalPixels, ICollection< T > transformedPixels, int order, out double quality)
 Create a non linear transformation that - approximately - matches the set of originalPixels to the set of transformedPixels . More...
 
static NonLinearTransformation FromPositionLists< T > (ICollection< T > originalPixels, ICollection< T > transformedPixels, int order, CreationProgress progressDelegate, out double quality)
 Create a non linear transformation that - approximately - matches the set of originalPixels to the set of transformedPixels . More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 IDispose helper function. More...
 

Properties

IntPtr Handle [get]
 Native non linear transformation handle. More...
 
bool IsDisposed [get]
 Tests if the native handle has already been disposed.
 
int Order [get]
 Transformation order.
 
ReadOnlyCollection< double > CoefficientsX [get]
 Return a read only array of the coefficients used for the transformation of x-coordinates.
 
ReadOnlyCollection< double > CoefficientsY [get]
 Return a read only array of the coefficients used for the transformation of y-coordinates.
 
ReadOnlyCollection< double > CoefficientsXInverse [get]
 Return a read only array of the coefficients used for the inverse transformation of x-coordinates.
 
ReadOnlyCollection< double > CoefficientsYInverse [get]
 Return a read only array of the coefficients used for the inverse transformation of y-coordinates.
 
- Properties inherited from INativeHandle
IntPtr Handle [get]
 The native handle of the object.
 
bool IsDisposed [get]
 Possibility to check whether the object has already been disposed of.
 

Events

NativeHandleEventDelegate ObjectDisposing
 Raised when this object is about to be disposed via the IDisposable.Dispose method. More...
 
- Events inherited from INativeHandle
NativeHandleEventDelegate ObjectDisposing
 Raised when this object is about to be disposed via the IDisposable.Dispose method.
More...
 

Detailed Description

Object implementing the non linear polynomially approximated transform implemented in the CVB Foundation Package.

Constructor & Destructor Documentation

◆ NonLinearTransformation()

NonLinearTransformation ( string  fileName)

Load a saved transformation from a file.

Parameters
fileNameName of the file to be loaded
Exceptions
FileNotFoundExceptionIf the transformation file does not exist
FileLoadExceptionIf loading an existing transformation file failed
ArgumentNullExceptionIf fileName is null

Member Function Documentation

◆ CreationProgress()

delegate bool CreationProgress ( int  stepsTotal,
int  stepsDone 
)

Delegate type of the progress callbacks that can be passed to some constructors of NonLinearTransformation for progress reporting.

Parameters
stepsTotalTotal number of calculation steps.
stepsDoneCalculation steps that have already been done.
Returns
Return true to continue calculation; false to cancel the process.

◆ Dispose()

virtual void Dispose ( bool  disposing)
protectedvirtual

IDispose helper function.

Parameters
disposingtrue when called via IDisposable.Dispose, false when called by the finalizer.

◆ FromCalibrationPattern() [1/4]

static NonLinearTransformation FromCalibrationPattern ( ImagePlane  plane,
Area2D  aoi,
CalibrationPatternStyle  style,
CalibrationPatternContrast  contrast,
int  gridSpacing,
int  minContrast,
double  maxRatio,
int  order,
CreationProgress  progressDelegate,
out double  quality 
)
static

Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object.

The image plane given to this method needs to contain a calibration pattern as generated by the method CalibrationPattern.Create(CalibrationPatternStyle, CalibrationPatternContrast, int, int, int, int): A regularly spaced matrix of dots, the distance between the dots in x- and y-direction should be 2.5 times the diameter of the dots, if an asymmetric pattern was used, the bigger dots should have 2.5 times the area of the smaller dots (meaning that their radius is sqrt(2.5) times the radius of the small dots).

Note that, although the area of interest is given as a Area2D here (and in the processing of the Area2D the image's coordinate system will be respected), the actual output of this method uses CoordinateSystemType.PixelCoordinates! This seemingly inconsistent mix in this case is in fact useful, because a Area2D will better capture the actual location of a calibration pattern, especially if the image has been rotated, than a Rect style area of interest. But the calibration functions working on the output of ExtractCalibrationLists usually assume that the pixel lists are given in pixel coordinates.

To avoid misunderstandings and complications in the interpretation of the image content, it is recommended to use a default coordinate system on the input image.

Parameters
planeImage plane to work on.
aoiArea of interest in which to look for the calibration pattern's dots.
styleCalibration pattern style visible in the image. (see CalibrationPatternStyle)
contrastSelects whether the image shows CalibrationPatternContrast.BlackOnWhite or CalibrationPatternContrast.WhiteOnBlack dots.
gridSpacingSpacing of the calibration dot grid in the target image.Defines the distance of the points that will end up in the transformed pixels.
minContrastMinimum gray value contrast between the object and the background of the calibration target pattern. Value to be set depends on the quality of the image taken from the pattern, but in a typical situation this contrast should not drop below 64 gray values, otherwise it might become difficult to extract the calibration points.
maxRatioMaximum ratio between the biggest and the smallest calibration dot.This value will be used to identify outliers when looking for calibration dots. It should be set high enough to allow for the area variations to be expected due to perspective distortions and small enough to eliminate the candidates that are either too big or too small to be valid calibration pattern dots. Typically, values of about 3.0 to 5.0 are big enough - even if there is notable perspective distortion visible in the images. If an asymmetric calibration pattern has been selected, the ratio used for calculation will be adapted accordingly.
orderPolynomial order of the transformation to be generated.
progressDelegatedelegate to be used for passing progress information back to the caller
qualityQuality feedback.Derived by correlating the application of the resulting transformation to the set of the calibration pattern.
Returns
Newly created calibration object.

◆ FromCalibrationPattern() [2/4]

static NonLinearTransformation FromCalibrationPattern ( ImagePlane  plane,
Area2D  aoi,
CalibrationPatternStyle  style,
CalibrationPatternContrast  contrast,
int  gridSpacing,
int  minContrast,
double  maxRatio,
int  order,
out double  quality 
)
static

Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object.

The image plane given to this method needs to contain a calibration pattern as generated by the method CalibrationPattern.Create(CalibrationPatternStyle, CalibrationPatternContrast, int, int, int, int): A regularly spaced matrix of dots, the distance between the dots in x- and y-direction should be 2.5 times the diameter of the dots, if an asymmetric pattern was used, the bigger dots should have 2.5 times the area of the smaller dots (meaning that their radius is sqrt(2.5) times the radius of the small dots).

Note that, although the area of interest is given as a Area2D here (and in the processing of the Area2D the image's coordinate system will be respected), the actual output of this method uses CoordinateSystemType.PixelCoordinates! This seemingly inconsistent mix in this case is in fact useful, because a Area2D will better capture the actual location of a calibration pattern, especially if the image has been rotated, than a Rect style area of interest. But the calibration functions working on the output of ExtractCalibrationLists usually assume that the pixel lists are given in pixel coordinates.

To avoid misunderstandings and complications in the interpretation of the image content, it is recommended to use a default coordinate system on the input image.

Parameters
planeImage plane to work on.
aoiArea of interest in which to look for the calibration pattern's dots.
styleCalibration pattern style visible in the image. (see CalibrationPatternStyle)
contrastSelects whether the image shows CalibrationPatternContrast.BlackOnWhite or CalibrationPatternContrast.WhiteOnBlack dots.
gridSpacingSpacing of the calibration dot grid in the target image.Defines the distance of the points that will end up in the transformed pixels.
minContrastMinimum gray value contrast between the object and the background of the calibration target pattern. Value to be set depends on the quality of the image taken from the pattern, but in a typical situation this contrast should not drop below 64 gray values, otherwise it might become difficult to extract the calibration points.
maxRatioMaximum ratio between the biggest and the smallest calibration dot.This value will be used to identify outliers when looking for calibration dots. It should be set high enough to allow for the area variations to be expected due to perspective distortions and small enough to eliminate the candidates that are either too big or too small to be valid calibration pattern dots. Typically, values of about 3.0 to 5.0 are big enough - even if there is notable perspective distortion visible in the images. If an asymmetric calibration pattern has been selected, the ratio used for calculation will be adapted accordingly.
orderPolynomial order of the transformation to be generated.
qualityQuality feedback.Derived by correlating the application of the resulting transformation to the set of the calibration pattern.
Returns
Newly created calibration object.

◆ FromCalibrationPattern() [3/4]

static NonLinearTransformation FromCalibrationPattern ( ImagePlane  plane,
CalibrationPatternStyle  style,
CalibrationPatternContrast  contrast,
int  gridSpacing,
int  minContrast,
double  maxRatio,
int  order,
CreationProgress  progressDelegate,
out double  quality 
)
static

Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object.

The image plane given to this method needs to contain a calibration pattern as generated by the method CalibrationPattern.Create(CalibrationPatternStyle, CalibrationPatternContrast, int, int, int, int): A regularly spaced matrix of dots, the distance between the dots in x- and y-direction should be 2.5 times the diameter of the dots, if an asymmetric pattern was used, the bigger dots should have 2.5 times the area of the smaller dots (meaning that their radius is sqrt(2.5) times the radius of the small dots).

Note that, although the area of interest is given as a Area2D here (and in the processing of the Area2D the image's coordinate system will be respected), the actual output of this method uses CoordinateSystemType.PixelCoordinates! This seemingly inconsistent mix in this case is in fact useful, because a Area2D will better capture the actual location of a calibration pattern, especially if the image has been rotated, than a Rect style area of interest. But the calibration functions working on the output of ExtractCalibrationLists usually assume that the pixel lists are given in pixel coordinates.

To avoid misunderstandings and complications in the interpretation of the image content, it is recommended to use a default coordinate system on the input image.

Parameters
planeImage plane to work on.
styleCalibration pattern style visible in the image. (see CalibrationPatternStyle)
contrastSelects whether the image shows CalibrationPatternContrast.BlackOnWhite or CalibrationPatternContrast.WhiteOnBlack dots.
gridSpacingSpacing of the calibration dot grid in the target image.Defines the distance of the points that will end up in the transformed pixels.
minContrastMinimum gray value contrast between the object and the background of the calibration target pattern. Value to be set depends on the quality of the image taken from the pattern, but in a typical situation this contrast should not drop below 64 gray values, otherwise it might become difficult to extract the calibration points.
maxRatioMaximum ratio between the biggest and the smallest calibration dot.This value will be used to identify outliers when looking for calibration dots. It should be set high enough to allow for the area variations to be expected due to perspective distortions and small enough to eliminate the candidates that are either too big or too small to be valid calibration pattern dots. Typically, values of about 3.0 to 5.0 are big enough - even if there is notable perspective distortion visible in the images. If an asymmetric calibration pattern has been selected, the ratio used for calculation will be adapted accordingly.
orderPolynomial order of the transformation to be generated.
progressDelegatedelegate to be used for passing progress information back to the caller
qualityQuality feedback.Derived by correlating the application of the resulting transformation to the set of the calibration pattern.
Returns
Newly created calibration object.

◆ FromCalibrationPattern() [4/4]

static NonLinearTransformation FromCalibrationPattern ( ImagePlane  plane,
CalibrationPatternStyle  style,
CalibrationPatternContrast  contrast,
int  gridSpacing,
int  minContrast,
double  maxRatio,
int  order,
out double  quality 
)
static

Create a new transformation object by automatically extracting the pixel lists required for creating a NonLinearTransformation object.

The image plane given to this method needs to contain a calibration pattern as generated by the method CalibrationPattern.Create(CalibrationPatternStyle, CalibrationPatternContrast, int, int, int, int): A regularly spaced matrix of dots, the distance between the dots in x- and y-direction should be 2.5 times the diameter of the dots, if an asymmetric pattern was used, the bigger dots should have 2.5 times the area of the smaller dots (meaning that their radius is sqrt(2.5) times the radius of the small dots).

To avoid misunderstandings and complications in the interpretation of the image content, it is recommended to use a default coordinate system on the input image.

Parameters
planeImage plane to work on.
styleCalibration pattern style visible in the image. (see CalibrationPatternStyle)
contrastSelects whether the image shows CalibrationPatternContrast.BlackOnWhite or CalibrationPatternContrast.WhiteOnBlack dots.
gridSpacingSpacing of the calibration dot grid in the target image.Defines the distance of the points that will end up in the transformed pixels.
minContrastMinimum gray value contrast between the object and the background of the calibration target pattern. Value to be set depends on the quality of the image taken from the pattern, but in a typical situation this contrast should not drop below 64 gray values, otherwise it might become difficult to extract the calibration points.
maxRatioMaximum ratio between the biggest and the smallest calibration dot.This value will be used to identify outliers when looking for calibration dots. It should be set high enough to allow for the area variations to be expected due to perspective distortions and small enough to eliminate the candidates that are either too big or too small to be valid calibration pattern dots. Typically, values of about 3.0 to 5.0 are big enough - even if there is notable perspective distortion visible in the images. If an asymmetric calibration pattern has been selected, the ratio used for calculation will be adapted accordingly.
orderPolynomial order of the transformation to be generated.
qualityQuality feedback.Derived by correlating the application of the resulting transformation to the set of the calibration pattern.
Returns
Newly created calibration object.

◆ FromPositionLists< T >() [1/2]

static NonLinearTransformation FromPositionLists< T > ( ICollection< T >  originalPixels,
ICollection< T >  transformedPixels,
int  order,
CreationProgress  progressDelegate,
out double  quality 
)
static

Create a non linear transformation that - approximately - matches the set of originalPixels to the set of transformedPixels .

Parameters
originalPixelsOriginial pixel locations.The pixels as measured from an image.
transformedPixelsTransformed pixels.The locations the corresponding pixels from originalPixels should ideally have.
orderPolynomial order of the transformation to be generated.
progressDelegateDelegate to be used for passing progress information back to the caller.
qualityQuality feedback.Derived by correlating the application of the resulting transformation to the set of originalPixels to the set of transformedPixels .
Returns
Transformation object.
Exceptions
ArgumentNullExceptionIf originalPixels or transformedPixels are null.
Template Parameters
TType of the defining pixel information. May be any type derived from the IPosition interface, i.e. search or blob results are directly eligible.
Type Constraints
T :IPosition 

◆ FromPositionLists< T >() [2/2]

static NonLinearTransformation FromPositionLists< T > ( ICollection< T >  originalPixels,
ICollection< T >  transformedPixels,
int  order,
out double  quality 
)
static

Create a non linear transformation that - approximately - matches the set of originalPixels to the set of transformedPixels .

Parameters
originalPixelsOriginial pixel locations.The pixels as measured from an image.
transformedPixelsTransformed pixels.The locations the corresponding pixels from originalPixels should ideally have.
orderPolynomial order of the transformation to be generated.
qualityQuality feedback.Derived by correlating the application of the resulting transformation to the set of originalPixels to the set of transformedPixels .
Returns
Transformation object.
Template Parameters
TType of the defining pixel information. May be any type derived from the IPosition interface, i.e. search or blob results are directly eligible.
Type Constraints
T :IPosition 

◆ InverseTransform() [1/3]

Point2Dd[] InverseTransform ( ICollection< IPosition points)

Back transform a sequence of points with this nonlinear transformation.

Parameters
pointsPoint to transform.
Returns
The transformed point.
Exceptions
ObjectDisposedExceptionIf this object or the has been disposed.
ArgumentNullExceptionIf points is null.

◆ InverseTransform() [2/3]

Image InverseTransform ( Image  img,
Size2D  targetSize,
Point2D  targetOffset 
)

Back-transform an image with this nonlinear transformation.

Parameters
imgImage to transform
targetSizeTarget size of the transformed image
targetOffsetOrigin offset of the transformed image
Returns
The transformed image.
Exceptions
ObjectDisposedExceptionIf this object or the img has been disposed.
ArgumentNullExceptionIf img is null.

◆ InverseTransform() [3/3]

Point2Dd InverseTransform ( IPosition  pt)

Back-Transform a point with this nonlinear transformation.

Parameters
ptPoint to transform.
Returns
The transformed point.
Exceptions
ObjectDisposedExceptionIf this object or the has been disposed.

◆ Save()

void Save ( string  fileName)

Write the transformation to a file.

Parameters
fileNamePath to save to.
Exceptions
ObjectDisposedExceptionIf the classifier has already been disposed.
ArgumentNullExceptionwhen fileName is null

◆ Transform() [1/4]

Point2Dd[] Transform ( ICollection< IPosition points)

Transform a sequence of points with this nonlinear transformation.

Parameters
pointsPoints to transform.
Returns
The transformed point.
Exceptions
ObjectDisposedExceptionIf this object or the has been disposed.
ArgumentNullExceptionIf points is null.

◆ Transform() [2/4]

Image Transform ( Image  img,
Size2D  targetSize,
Point2D  targetOffset 
)

Transform an image with this nonlinear transformation.

Parameters
imgImage to be transformed
targetSizeTarget size of the transformed image.
targetOffsetOrigin offset of the transformed image.
Returns
The transformed image.
Exceptions
ObjectDisposedExceptionIf this object or the img has been disposed.
ArgumentNullExceptionIf img is null.

◆ Transform() [3/4]

Point2Dd Transform ( IPosition  pt)

Transform a point with this nonlinear transformation.

Parameters
ptPoints to transform.
Returns
The transformed point.
Exceptions
ObjectDisposedExceptionIf this object or the has been disposed.

◆ Transform() [4/4]

RectD Transform ( RectD  rect)

Transform a rect with this nonlinear transformation.

The transformed rect is a best guess of the target dimensions needed for a transformed image. Due to the non linearity of the transformation it may not be correct. Consider it a best guess.

Parameters
rectRect to transform.
Returns
The transformed rect.

Property Documentation

◆ Handle

IntPtr Handle
get

Native non linear transformation handle.

It is normally not necessary to work with this handle in CVB.Net. Note that using this handle in connection with the legacy CVB managed wrappers may actually be disruptive to your application.

Implements INativeHandle.

Event Documentation

◆ ObjectDisposing

NativeHandleEventDelegate ObjectDisposing

Raised when this object is about to be disposed via the IDisposable.Dispose method.

This event is raised right before this object is disposed. The dispose itself cannot be canceled.