Into

Modules

Documentation

namespace referencePiiTransforms

A namespace for functions that transform images into different types of domains.

Classes

struct

A function object that randomly selects pixels whose gradient magnitude is higher than or equal to threshold.

struct

A function object that selects pixels whose gradient magnitude is higher than or equal to threshold.

Enumerations

enum
{ PositiveGradient = 1, NegativeGradient = 2, IgnoreGradientSign = 3 }

Functions

template<class T, class Selector, class U>
PiiMatrix< U >
(
  • const PiiMatrix< T > & gradientX
  • const PiiMatrix< T > & gradientY
  • Selector select
  • U radius
  • double angleError
  • GradientSign sign = IgnoreGradientSign
)

Circular Hough transform.

template<class T, class Selector, class U>
QList< PiiMatrix< U > >
(
  • const PiiMatrix< T > & image
  • Selector select
  • U startRadius
  • U endRadius
  • U radiusStep = 1
  • GradientSign sign = IgnoreGradientSign
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version uses the Sobel edge detector to first estimate gradient in image.

PII_TRANSFORMS_EXPORT PeakList
( )

Find peaks in the Hough transform domain.

template<class T, class U, class UnaryOp>
PiiMatrix< T >
(
  • const PiiMatrix< U > & img
  • UnaryOp rule
  • double angleResolution = 1.0
  • double distanceResolution = 1.0
  • int angleStart = 0
  • int angleEnd = 180
  • int distanceStart = < int >::minValue()
  • int distanceEnd = < int >::maxValue()
)

Linear Hough transform.

PII_TRANSFORMS_EXPORT PiiMatrix< double >
(
  • double d
  • double theta
  • int rows
  • int columns
)

Convert the rescaled peak coordinates into points on the boundary of an image with the given number of rows and columns.

double
(
  • int column
  • int angleStart = 0
  • double angleResolution = 1.0
)

Rescale the angle (column) coordinate in a Hough transform accumulator.

double
(
  • int row
  • int rows = 0
  • int columns = 0
  • double distanceResolution = 1.0
  • double distanceStart = < int >::minValue()
)

Rescale the distance (row) coordinate in a Hough transform accumulator.

Enumeration details

  • enum GradientSign

Function details

  • template<class T, class Selector, class U>

    PiiMatrix< U > circularHough

    (
    • const PiiMatrix< T > & gradientX
    • const PiiMatrix< T > & gradientY
    • Selector select
    • U radius
    • double angleError
    • GradientSign sign = IgnoreGradientSign
    )

    #include <PiiTransforms.h>

    Circular Hough transform.

    The circular Hough transform detects circles in images. Circles are parametrized by their center (x,y) and radius (r), resulting in a three-dimensional transform domain. This function calculates a slice of the three-dimensional domain specific to a known radius r.

     PiiMatrix<unsigned char> matInput; // input image
     PiiMatrix<GradType> matGradX(PiiImage::filter<int>(matInput, PiiImage::SobelXFilter));
     PiiMatrix<GradType> matGradY(PiiImage::filter<int>(matInput, PiiImage::SobelYFilter));
     using namespace PiiTransforms;
     PiiMatrix<int> matTransform(circularHough(matGradX, matGradY,
                                               ThresholdSelector(5.0),
                                               5,
                                               0.01));
    
    Parameters
    gradientX

    estimated magnitude of horizontal image gradient. (e.g. image filtered with the SobelX filter)

    gradientY
    select
    radius

    the radius of the circles to be found. If this value is a double, the returned matrix will also be a double, and a floating-point (more accurate) algorithm will be used. If this value is an int, a faster integer algorithm will be used.

    angleError

    an esimate of angular error in the calculated gradients. Setting angleError to a non-zero value will increase accuracy but also slow down the algorithm.

    sign
    Returns

    the transformation domain. Each pixel in the transformation domain stores the number of times it was accessed during the algorithm. With the floating point version, the counts are weighted with gradient magnitude. A high value means that a circle with the given radius is centered at that pixel with a high likelihood.

  • template<class T, class Selector, class U>

    QList< PiiMatrix< U > > circularHough

    (
    • const PiiMatrix< T > & image
    • Selector select
    • U startRadius
    • U endRadius
    • U radiusStep = 1
    • GradientSign sign = IgnoreGradientSign
    )

    #include <PiiTransforms.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version uses the Sobel edge detector to first estimate gradient in image.

    Then, it applies circularHough() to all radii in [startRadius, endRadius] in radiusStep steps.

     using namespace PiiTransforms;
     QList<PiiMatrix<int> > lstMatrices(circularHough(matInput,
                                                      RandomSelector(1.0, 0.1), // Selects one tenth of pixels
                                                      10, 20, 2)); // Scan radii from 10 to 20 in 2 pixel steps
    
    Returns

    a transformation domain for each inspected radius

  • PII_TRANSFORMS_EXPORT PeakList findPeaks

    ( )

    #include <PiiTransforms.h>

    Find peaks in the Hough transform domain.

    This function differs from Pii::findMaxima() in that it considers only local maxima and never returns two peaks that are (4-connected) neighbors to each other in the transformation domain.

    Parameters
    transformation

    the result of a Hough transform

    cnt

    the number of highest peaks to return

    Returns

    a list of detected peaks

  • template<class T, class U, class UnaryOp>

    PiiMatrix< T > linearHough

    (
    • const PiiMatrix< U > & img
    • UnaryOp rule
    • double angleResolution = 1.0
    • double distanceResolution = 1.0
    • int angleStart = 0
    • int angleEnd = 180
    • int distanceStart = < int >::minValue()
    • int distanceEnd = < int >::maxValue()
    )

    #include <PiiTransforms.h>

    Linear Hough transform.

    The linear Hough transform is used in detecting lines in images. Lines are paramerized by their slope and distance to the origin, resulting in a two-dimensional transformation domain. In the transformation domain, columns represent slopes and rows distances to the origin. The origin of the domain is at the center of the image. The quantization of the transformation domain is user-specifiable.

    The number of rows in the result will always be odd. The row at the middle always represents lines that intersect the origin (i.e. distance zero). If distanceResolution is 1.0 (the default), moving up or down from the middle row increases distance to the origin by one pixel. The first column represents lines with a zero slope. If angleResolution is 1.0 (the default), the next column represents lines with a 1 degree slope and so on. Zero angle points downwards, and the angle grows clockwise. This peculiar choice was made to make it easy to calculate the resulting lines in image coordinates (x is columns and y is rows, positive y axis downwards).

    Formally, the detected lines are parametrized with the following equation:

    where stands for the angle, and d is the "distance" from origin (d can be negative). If you pick a value from the transform domain, its row and column coordinates tell the values of d and , respectively. Once these are known, it is straightforward to solve x with respect to y or vice versa.

    Note that the transform adds the value of a transformed pixel to the transformation domain (a.k.a. the accumulator). If the input image is binary, each pixel will have an equal effect. Higher values can be used in giving higher significance to certain pixels.

     PiiMatrix<int> img; // fill somehow...
     // Make the Hough transform. The result will be a PiiMatrix<int>,
     // and each pixel with a value higher than or equal to three will
     // be transformed. The angles will be quantized to 90 discrete
     // levels (2 degrees each)
        
     double distanceResolution = 1.0;
     double angleResolution = 2.0;
     PiiMatrix<int> result(PiiTransforms::linearHough<int>(img,
                                                           std::bind2nd(std::greater<int>(), 3),
                                                           angleResolution,
                                                           distanceResolution));
    
    Parameters
    img

    the input image. The image will be scanned, and each pixel that makes evaluator evaluate true will be added to the parameter space. Typically, the input image is binary.

    rule

    the is unary operator which is used to determine if a pixel may be part of a line.

    angleResolution

    the number of degrees each column represents. The default value is 1.0 which produces 180 columns in the result matrix.

    distanceResolution

    the distance (in pixels) each row represents.

    angleStart

    the start angle of the transformation domain. The default value is zero, which places zero angle to the leftmost column. This value can be negative.

    angleEnd

    the end angle of the transformation domain. This value with angleStart can be used to limit the line search to a certain range of angles. Note that the last angle will not be present in the transformation. That is, if angleEnd is 180 (the default) and angleResolution is 1, the last angle will be 179.

    distanceStart

    the smallest (signed) distance to the origin considered in the transformation. If the distance is smaller than the minimum possible distance, the theoretical minimum will be used.

    distanceEnd

    the largest (signed) distance to the origin considered in the transformation. If the distance is larger than the maximum possible distance, the theoretical maximum will be used.

    Returns

    the accumulator array. The size of the returned matrix depends on angle and distance limits and their resolution.

  • PII_TRANSFORMS_EXPORT PiiMatrix< double > peakToPoints

    (
    • double d
    • double theta
    • int rows
    • int columns
    )

    #include <PiiTransforms.h>

    Convert the rescaled peak coordinates into points on the boundary of an image with the given number of rows and columns.

     using namespace PiiTransforms;
     // Transform an image
     PiiMatrix<int> matTransformed(linearHough<int>(img, std::bind2nd(std::greater<int>(), 0)));
     // Find 10 highest peaks in the transformation domain
     PiiHeap<PiiMatrixValue<int>,16> maxima = Pii::findMaxima(matTransformed, 10);
     PiiMatrix<double> matPoints(0,4);
     for (int i=0; i<maxima.size(); ++i)
       matPoints.insertRow(peakToPoints(rescaleHoughDistance(maxima[i].row, img.rows(), img.columns()),
                                        rescaleHoughAngle(maxima[i].column), // not necessary
                                        img.rows(), img.columns()));
    
    Parameters
    d

    the distance of the line to the transform's origin

    theta

    the angle of the line, in degrees.

    rows
    columns
    Returns

    a 1-by-4 matrix storing the start and end points of a line segment (x1, y1, x2, y2). The returned value is suitable for use with PiiImageAnnotator's property input.

    See also
  • double rescaleHoughAngle

    (
    • int column
    • int angleStart = 0
    • double angleResolution = 1.0
    )
    [inline]

    #include <PiiTransforms.h>

    Rescale the angle (column) coordinate in a Hough transform accumulator.

    Parameters
    column

    a column index in the result of a Hough transform.

    angleStart

    the value of the angleStart parameter used in the Hough transform.

    angleResolution

    the value of the angleResolution parameter used in the Hough transform

    Returns

    angleResolution * column + angleStart

  • double rescaleHoughDistance

    (
    • int row
    • int rows = 0
    • int columns = 0
    • double distanceResolution = 1.0
    • double distanceStart = < int >::minValue()
    )
    [inline]

    #include <PiiTransforms.h>

    Rescale the distance (row) coordinate in a Hough transform accumulator.

    Parameters
    row

    a row index in the result of a Hough transform.

    rows

    the number of rows in the source image. Needed if distanceStart is not specified.

    columns

    the number of columns in the source image. Needed if distanceStart is not specified.

    distanceResolution

    the value of the distanceResolution parameter used in the Hough transform

    distanceStart

    the value of the distanceStart parameter used in the Hough transform. This value must be specified if you leave rows and columns to zero.

    Returns

    the distance ot the origin of the image domain corresponding to row in a transformation result, in pixels

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.