Class HoughTransformLines

java.lang.Object
imagingbook.common.hough.HoughTransformLines
All Implemented Interfaces:
ProgressReporter

public class HoughTransformLines extends Object implements ProgressReporter

This class implements the "classic" Hough Transform for straight lines. This implementation improves the algorithm described in the textbook in the way the accumulator is updated. Here, the quantity 1 is not added to a single accumulator cell but gets distributed over two neighboring (radial) cells to reduce aliasing effects. Thus we accumulate non-integer values and therefore the various accumulators are of type float[][]. See Sec. 12.2 of [1] for additional details.

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

Version:
2022/09/10 removed ImageJ progress reporting
  • Constructor Details

    • HoughTransformLines

      Constructor, creates a new Hough transform from the binary image.
      Parameters:
      I - input image, relevant (edge) points have pixel values greater 0.
      params - parameter object.
    • HoughTransformLines

    • HoughTransformLines

      public HoughTransformLines(Pnt2d[] points, int width, int height, HoughTransformLines.Parameters params)
      Constructor, creates a new Hough transform from a sequence of 2D points. Parameters M, N are only used to specify the reference point (usually at the center of the image). Use this constructor if the relevant image points are collected separately.
      Parameters:
      points - an array of 2D points.
      width - width of the corresponding image plane.
      height - height of the corresponding image plane.
      params - parameter object.
  • Method Details

    • getLines

      public HoughLine[] getLines(int amin, int maxLines)
      Finds and returns the parameters of the strongest lines with a specified min. pixel count. All objects in the returned array are valid, but the array may be empty. Note: Could perhaps be implemented more efficiently with insert-sort.
      Parameters:
      amin - the minimum accumulator value for each line.
      maxLines - maximum number of (strongest) lines to extract.
      Returns:
      a possibly empty array of HoughLine objects.
    • getXref

      public double getXref()
      Returns the reference points x-coordinate.
      Returns:
      as described.
    • getYref

      public double getYref()
      Returns the reference points y-coordinate.
      Returns:
      as described.
    • angleFromIndex

      public double angleFromIndex(int ai)
      Calculates the actual angle (in radians) for angle index ai
      Parameters:
      ai - angle index [0,...,nAng-1]
      Returns:
      Angle [0,...,PI] for angle index ai
    • radiusFromIndex

      public double radiusFromIndex(int ri)
      Calculates the actual radius for radius index ri.
      Parameters:
      ri - radius index [0,...,nRad-1].
      Returns:
      Radius [-maxRad,...,maxRad] with respect to reference point (xc, yc).
    • radiusToIndex

      public double radiusToIndex(double rad)
    • getAccumulator

      public float[][] getAccumulator()
      Returns the accumulator as a 2D float-array.
      Returns:
      the contents of the accumulator
    • getAccumulatorMax

      public float[][] getAccumulatorMax()
      Returns the local maximum values of the accumulator as a 2D float-array (all non-maximum elements are set to zero).
      Returns:
      the local maximum values of the accumulator
    • getAccumulatorExtended

      public float[][] getAccumulatorExtended()
      Returns the extended accumulator as a 2D float-array.
      Returns:
      the extended accumulator
    • getAccumulatorImage

      Creates and returns an image of the 2D accumulator array.
      Returns:
      a FloatProcessor image of the accumulator
    • getAccumulatorImageExtended

      Creates and returns an image of the extended 2D accumulator array, produced by adding a vertically mirrored copy of the accumulator to its right end.
      Returns:
      a FloatProcessor image of the extended accumulator
    • getAccumulatorMaxImage

      Creates and returns an image of the local maxima of the 2D accumulator array.
      Returns:
      a FloatProcessor image of the accumulator maxima
    • getProgress

      public double getProgress()
      Description copied from interface: ProgressReporter
      Returns a value in [0,1) indicating to which degree this task is complete.
      Specified by:
      getProgress in interface ProgressReporter
      Returns:
      a value between 0 and 1