Class IncrementalLineFit

java.lang.Object
imagingbook.common.geometry.fitting.line.IncrementalLineFit
All Implemented Interfaces:
LineFit

public class IncrementalLineFit extends Object implements LineFit

This class implements incremental orthogonal line fitting to a set of 2D points using eigendecomposition (see OrthogonalLineFitEigen for a non-incremental version). See Sec. 10.3 (Alg. 10.4) of [1] for additional details.

This fitter behaves like a queue: sample points may be added and removed freely either at its front or its end, while the ordering of the remaining points remains unchanged. This is to simplify back-tracking, for example for incremental contour fitting. Whenever a point is added or removed, the internal statistics (scatter matrix) are updated. The current line fit can be queried any time as long as there are more than two points in the point set (otherwise an exception is thrown).

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

Version:
2022/09/29 revised
See Also:
  • Constructor Details

    • IncrementalLineFit

      Constructor creating a fitter with an empty set of points.
    • IncrementalLineFit

      public IncrementalLineFit(Pnt2d[] initPnts)
      Constructor accepting a sequence of initial points. The first point is placed at the from of the queue, the last point at its end.
      Parameters:
      initPnts - an array of initial points
  • Method Details

    • getSquaredOrthogonalError

      public double getSquaredOrthogonalError()
      Calculates and returns the sum of the squared orthogonal distances of the current point set for this line fit.
      Returns:
      the squared orthogonal error
      See Also:
    • getPoints

      public Pnt2d[] getPoints()
      Returns the current point sequence of this fit as an array.
      Returns:
      an array of points
    • add

      public boolean add(Pnt2d pnt)
      Adds a new sample points to the end of the point sequence (same as addLast(Pnt2d)).
      Parameters:
      pnt - the point to be added
      Returns:
      true (always, to be compatible with Deque)
    • addFirst

      public void addFirst(Pnt2d pnt)
      Adds a new sample points to the front of the point sequence.
      Parameters:
      pnt - the point to be added
    • addLast

      public void addLast(Pnt2d pnt)
      Adds a new sample points to the end of the point sequence (same as addLast(Pnt2d)).
      Parameters:
      pnt - the point to be added
    • removeFirst

      public Pnt2d removeFirst()
      Retrieves and removes the first point from the front of the point sequence.
      Returns:
      the removed point
    • removeLast

      public Pnt2d removeLast()
      Retrieves and removes the last point from the end of the point sequence.
      Returns:
      the removed point
    • peekFirst

      public Pnt2d peekFirst()
      Returns (but does not remove) the point positioned at the front of the point sequence.
      Returns:
      the first point
    • peekLast

      public Pnt2d peekLast()
      Returns (but does not remove) the point positioned at the end of the point sequence.
      Returns:
      the last point
    • getSize

      public int getSize()
      Description copied from interface: LineFit
      Returns the size of the point set used for calculating this line fit.
      Specified by:
      getSize in interface LineFit
      Returns:
      the number of sample points used for fitting
    • getLineParameters

      public double[] getLineParameters()
      Description copied from interface: LineFit
      Returns the parameters [A, B, C] for the AlgebraicLine associated with this line fit. To be implemented by concrete classes. null is returned if no fit was found.
      Specified by:
      getLineParameters in interface LineFit
      Returns:
      algebraic line parameters [A, B, C]
      See Also: