ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
lsd.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <float.h>
#include "lsd.h"
Include dependency graph for lsd.c:

Go to the source code of this file.

Classes

struct  coorlist
 
struct  point
 
struct  ntuple_list_s
 
struct  image_char_s
 
struct  image_int_s
 
struct  image_double_s
 
struct  rect
 
struct  rect_iter
 

Macros

#define M_LN10   2.30258509299404568402
 
#define M_PI   3.14159265358979323846
 
#define FALSE   0
 
#define TRUE   1
 
#define NOTDEF   -1024.0
 
#define M_3_2_PI   4.71238898038
 
#define M_2__PI   6.28318530718
 
#define NOTUSED   0
 
#define USED   1
 
#define RELATIVE_ERROR_FACTOR   100.0
 
#define log_gamma(x)   ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x))
 
#define TABSIZE   100000
 

Typedefs

typedef struct ntuple_list_sntuple_list
 
typedef struct image_char_simage_char
 
typedef struct image_int_simage_int
 
typedef struct image_double_simage_double
 

Functions

static void error (char *msg)
 
static int double_equal (double a, double b)
 
static double dist (double x1, double y1, double x2, double y2)
 
static void free_ntuple_list (ntuple_list in)
 
static ntuple_list new_ntuple_list (unsigned int dim)
 
static void enlarge_ntuple_list (ntuple_list n_tuple)
 
static void add_7tuple (ntuple_list out, double v1, double v2, double v3, double v4, double v5, double v6, double v7)
 
static void free_image_char (image_char i)
 
static image_char new_image_char (unsigned int xsize, unsigned int ysize)
 
static image_char new_image_char_ini (unsigned int xsize, unsigned int ysize, unsigned char fill_value)
 
static image_int new_image_int (unsigned int xsize, unsigned int ysize)
 
static image_int new_image_int_ini (unsigned int xsize, unsigned int ysize, int fill_value)
 
static void free_image_double (image_double i)
 
static image_double new_image_double (unsigned int xsize, unsigned int ysize)
 
static image_double new_image_double_ptr (unsigned int xsize, unsigned int ysize, double *data)
 
static void gaussian_kernel (ntuple_list kernel, double sigma, double mean)
 
static image_double gaussian_sampler (image_double in, double scale, double sigma_scale)
 
static image_double ll_angle (image_double in, double threshold, struct coorlist **list_p, void **mem_p, image_double *modgrad, unsigned int n_bins)
 
static int isaligned (int x, int y, image_double angles, double theta, double prec)
 
static double angle_diff (double a, double b)
 
static double angle_diff_signed (double a, double b)
 
static double log_gamma_lanczos (double x)
 
static double log_gamma_windschitl (double x)
 
static double nfa (int n, int k, double p, double logNT)
 
static void rect_copy (struct rect *in, struct rect *out)
 
static double inter_low (double x, double x1, double y1, double x2, double y2)
 
static double inter_hi (double x, double x1, double y1, double x2, double y2)
 
static void ri_del (rect_iter *iter)
 
static int ri_end (rect_iter *i)
 
static void ri_inc (rect_iter *i)
 
static rect_iterri_ini (struct rect *r)
 
static double rect_nfa (struct rect *rec, image_double angles, double logNT)
 
static double get_theta (struct point *reg, int reg_size, double x, double y, image_double modgrad, double reg_angle, double prec)
 
static void region2rect (struct point *reg, int reg_size, image_double modgrad, double reg_angle, double prec, double p, struct rect *rec)
 
static void region_grow (int x, int y, image_double angles, struct point *reg, int *reg_size, double *reg_angle, image_char used, double prec)
 
static double rect_improve (struct rect *rec, image_double angles, double logNT, double log_eps)
 
static int reduce_region_radius (struct point *reg, int *reg_size, image_double modgrad, double reg_angle, double prec, double p, struct rect *rec, image_char used, image_double angles, double density_th)
 
static int refine (struct point *reg, int *reg_size, image_double modgrad, double reg_angle, double prec, double p, struct rect *rec, image_char used, image_double angles, double density_th)
 
double * LineSegmentDetection (int *n_out, double *img, int X, int Y, double scale, double sigma_scale, double quant, double ang_th, double log_eps, double density_th, int n_bins, int **reg_img, int *reg_x, int *reg_y)
 
double * lsd_scale_region (int *n_out, double *img, int X, int Y, double scale, int **reg_img, int *reg_x, int *reg_y)
 
double * lsd_scale (int *n_out, double *img, int X, int Y, double scale)
 
double * lsd (int *n_out, double *img, int X, int Y)
 

Detailed Description

LSD module code

Author
rafael grompone von gioi gromp.nosp@m.one@.nosp@m.gmail.nosp@m..com

Definition in file lsd.c.

Macro Definition Documentation

◆ FALSE

#define FALSE   0

Definition at line 115 of file lsd.c.

◆ log_gamma

#define log_gamma (   x)    ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x))

Computes the natural logarithm of the absolute value of the gamma function of x. When x>15 use log_gamma_windschitl(), otherwise use log_gamma_lanczos().

Definition at line 1025 of file lsd.c.

◆ M_2__PI

#define M_2__PI   6.28318530718

2 pi

Definition at line 129 of file lsd.c.

◆ M_3_2_PI

#define M_3_2_PI   4.71238898038

3/2 pi

Definition at line 126 of file lsd.c.

◆ M_LN10

#define M_LN10   2.30258509299404568402

ln(10)

Definition at line 106 of file lsd.c.

◆ M_PI

#define M_PI   3.14159265358979323846

PI

Definition at line 111 of file lsd.c.

◆ NOTDEF

#define NOTDEF   -1024.0

Label for pixels with undefined gradient.

Definition at line 123 of file lsd.c.

◆ NOTUSED

#define NOTUSED   0

Label for pixels not used in yet.

Definition at line 132 of file lsd.c.

◆ RELATIVE_ERROR_FACTOR

#define RELATIVE_ERROR_FACTOR   100.0

Doubles relative error factor

Definition at line 168 of file lsd.c.

◆ TABSIZE

#define TABSIZE   100000

Size of the table to store already computed inverse values.

Definition at line 1030 of file lsd.c.

◆ TRUE

#define TRUE   1

Definition at line 119 of file lsd.c.

◆ USED

#define USED   1

Label for pixels already used in detection.

Definition at line 135 of file lsd.c.

Typedef Documentation

◆ image_char

typedef struct image_char_s * image_char

char image data type

The pixel value at (x,y) is accessed by:

image->data[ x + y * image->xsize ]

with x and y integer.

◆ image_double

typedef struct image_double_s * image_double

double image data type

The pixel value at (x,y) is accessed by:

image->data[ x + y * image->xsize ]

with x and y integer.

◆ image_int

typedef struct image_int_s * image_int

int image data type

The pixel value at (x,y) is accessed by:

image->data[ x + y * image->xsize ]

with x and y integer.

◆ ntuple_list

typedef struct ntuple_list_s * ntuple_list

'list of n-tuple' data type

The i-th component of the j-th n-tuple of an n-tuple list 'ntl' is accessed with:

ntl->values[ i + j * ntl->dim ]

The dimension of the n-tuple (n) is:

ntl->dim

The number of n-tuples in the list is:

ntl->size

The maximum number of n-tuples that can be stored in the list with the allocated memory at a given time is given by:

ntl->max_size

Function Documentation

◆ add_7tuple()

static void add_7tuple ( ntuple_list  out,
double  v1,
double  v2,
double  v3,
double  v4,
double  v5,
double  v6,
double  v7 
)
static

Add a 7-tuple to an n-tuple list.

Definition at line 305 of file lsd.c.

◆ angle_diff()

static double angle_diff ( double  a,
double  b 
)
static

Absolute value angle difference.

Definition at line 931 of file lsd.c.

References M_2__PI, and M_PI.

Referenced by get_theta().

◆ angle_diff_signed()

static double angle_diff_signed ( double  a,
double  b 
)
static

Signed angle difference.

Definition at line 943 of file lsd.c.

References M_2__PI, and M_PI.

◆ dist()

static double dist ( double  x1,
double  y1,
double  x2,
double  y2 
)
static

Computes Euclidean distance between point (x1,y1) and point (x2,y2).

Definition at line 207 of file lsd.c.

Referenced by flann::HellingerDistance< T >::accum_dist(), qCanupo2DViewDialog::addOrSelectPoint(), flann::KNNSimpleResultSet< DistanceType >::addPoint(), flann::KNNResultSet< DistanceType >::addPoint(), flann::KNNResultSet2< DistanceType >::addPoint(), flann::RadiusResultSet< DistanceType >::addPoint(), flann::KNNRadiusResultSet< DistanceType >::addPoint(), flann::CountRadiusResultSet< DistanceType >::addPoint(), flann::KNNUniqueResultSet< DistanceType >::addPoint(), flann::RadiusUniqueResultSet< DistanceType >::addPoint(), flann::KMeansIndex< Distance >::addPoints(), allocateBtreePage(), cloudViewer::visualization::rendering::MatrixInteractorLogic::CalcDollyDist(), cloudViewer::visualization::rendering::RotationInteractorLogic::CalcPanVectorWorld(), ccPointPairRegistrationDlg::callHornRegistration(), ccAlignDlg::changeSamplingMethod(), cloudViewer::KDTree::checkDistantPointInSubTree(), cloudViewer::KDTree::checkNearerPointInSubTree(), cloudViewer::DistanceComputationTools::computeCellHausdorffDistance(), cloudViewer::DistanceComputationTools::computeCloud2BoxEquation(), cloudViewer::DistanceComputationTools::computeCloud2MeshDistanceWithOctree(), cloudViewer::DistanceComputationTools::computeCloud2RectangleEquation(), LSLocalModel::computeDistanceFromModelToPoint(), ComputeM3C2DistForPoint(), ComputeNeighborhood2MeshDistancesWithOctree(), DistanceMapGenerationTool::ComputeRadialDist(), flann::UniqueResultSet< DistanceType >::copy(), cloudViewer::visualization::rendering::GeometryBuffersBuilder::CreateIndexBuffer(), cloudViewer::GeometricalAnalysisTools::DetectSphereRobust(), cloudViewer::KDTree::distanceScanTree(), cloudViewer::visualization::rendering::MatrixInteractorLogic::Dolly(), flann::ensureSquareDistance(), ccCompass::estimateStructureNormals(), cloudViewer::t::geometry::npp::FilterGaussian(), flann::LinearIndex< Distance >::findNeighbors(), G3Point::getRandomColors(), cloudViewer::visualization::rendering::Gradient::GetTextureHandle(), flann::cuda::SingleResultSet< DistanceType >::insert(), flann::cuda::KnnResultSet< DistanceType, useHeap >::insert(), flann::cuda::RadiusKnnResultSet< DistanceType, useHeap >::insert(), flann::cuda::KnnRadiusResultSet< DistanceType, useHeap >::insert(), flann::cuda::RadiusResultSet< DistanceType >::insert(), flann::cuda::CountingRadiusResultSet< DistanceType >::insert(), flann::KDTreeCuda3dIndex< Distance >::knnSearchGpu(), cloudViewer::utility::IntersectionTest::LineSegmentsMinimumDistance(), cloudViewer::utility::IntersectionTest::LinesMinimumDistance(), cloudViewer::visualization::gui::PickPointsInteractor::OnPickImageDone(), flann::GonzalesCenterChooser< Distance >::operator()(), flann::KMeansppCenterChooser< Distance >::operator()(), flann::squareDistance< Distance, ElementType >::operator()(), flann::squareDistance< L2_Simple< ElementType >, ElementType >::operator()(), flann::squareDistance< L2_3D< ElementType >, ElementType >::operator()(), flann::squareDistance< L2< ElementType >, ElementType >::operator()(), flann::squareDistance< HellingerDistance< ElementType >, ElementType >::operator()(), flann::squareDistance< ChiSquareDistance< ElementType >, ElementType >::operator()(), ccThicknessTool::pointPicked(), knncpp::QueryHeap< Scalar >::pop(), FacetsClassifier::ProcessFamiliy(), knncpp::QueryHeap< Scalar >::push(), knncpp::BruteForce< Scalar, Distance >::query(), knncpp::MultiIndexHashing< Scalar >::query(), cloudViewer::benchmarks::Rand(), reduce_region_radius(), cloudViewer::CloudSamplingTools::resampleCloudSpatially(), cloudViewer::visualization::rendering::MatrixInteractorLogic::Rotate(), cloudViewer::visualization::rendering::CameraSphereInteractorLogic::Rotate(), cloudViewer::visualization::rendering::MatrixInteractorLogic::RotateWorld(), cloudViewer::MeshSamplingTools::samplePointsOnMesh(), flann::search_with_ground_truth(), cloudViewer::ManualSegmentationTools::segment(), cloudViewer::visualization::gui::SceneWidget::SetupCamera(), knncpp::QueryHeap< Scalar >::sort(), cloudViewer::CloudSamplingTools::subsampleCloudRandomly(), flann::test_index_checks(), flann::test_index_precision(), flann::test_index_precisions(), cloudViewer::visualization::gui::FlyInteractor::Tick(), and G3Point::G3PointAction::wolman().

◆ double_equal()

static int double_equal ( double  a,
double  b 
)
static

Compare doubles by relative error.

The resulting rounding error after floating point computations depend on the specific operations done. The same number computed by different algorithms could present different rounding errors. For a useful comparison, an estimation of the relative rounding error should be considered and compared to a factor times EPS. The factor should be related to the cumulated rounding error in the chain of computation. Here, as a simplification, a fixed factor is used.

Definition at line 181 of file lsd.c.

References fabs(), RELATIVE_ERROR_FACTOR, and TRUE.

Referenced by get_theta(), inter_hi(), inter_low(), and nfa().

◆ enlarge_ntuple_list()

static void enlarge_ntuple_list ( ntuple_list  n_tuple)
static

Enlarge the allocated memory of an n-tuple list.

Definition at line 287 of file lsd.c.

References ntuple_list_s::dim, error(), ntuple_list_s::max_size, NULL, and ntuple_list_s::values.

◆ error()

static void error ( char *  msg)
static

Fatal error, print a message to standard-error output and exit.

Definition at line 159 of file lsd.c.

Referenced by FastMarchingForFacetExtraction::addCellToCurrentFacet(), qCanupoClassifDialog::browseClassifierFile(), FacetsClassifier::ByOrientation(), cloudViewer::t::io::RealSenseSensor::CaptureFrame(), CCMeshToDraco(), masc::Feature::checkValidity(), masc::ContextBasedFeature::checkValidity(), masc::DualCloudFeature::checkValidity(), masc::NeighborhoodFeature::checkValidity(), masc::PointFeature::checkValidity(), qCanupoProcess::Classify(), DONSegmentation::compute(), EuclideanClusterSegmentation::compute(), SACSegmentation::compute(), qM3C2Process::Compute(), ComputeCellStats(), ComputeClusterVolume(), qCanupoTools::ComputeCorePointsDescriptors(), ComputeMathOpWithNearestNeighbor(), cloudViewer::t::pipelines::registration::TransformationEstimationPointToPoint::ComputeRMSE(), cloudViewer::t::pipelines::registration::TransformationEstimationPointToPlane::ComputeRMSE(), cloudViewer::t::pipelines::registration::TransformationEstimationForDopplerICP::ComputeRMSE(), qFacets::createFacets(), define_qcc_io(), define_TrueKdTree(), cloudViewer::utility::filesystem::DeleteDirectory(), cloudViewer::GeometricalAnalysisTools::DetectCircle(), cloudViewer::GeometricalAnalysisTools::DetectSphereRobust(), q3DMASCPlugin::doClassifyAction(), qCanupoPlugin::doClassifyAction(), q3DMASCPlugin::doTrainAction(), enlarge_ntuple_list(), ccRasterizeTool::ExportGeoTiff(), qFacets::extractFacets(), masc::ContextBasedFeature::finish(), masc::NeighborhoodFeature::finish(), masc::PointFeature::finish(), QuaZIODevice::flush(), free_image_char(), free_image_double(), ccKdTreeForFacetExtraction::FuseCells(), ccRasterizeTool::generateContours(), get_theta(), LasScalarFieldLoader::handleScalarFields(), FastMarchingForFacetExtraction::init(), PythonInterpreter::initialize(), inter_hi(), inter_low(), isaligned(), ProfileLoader::Load(), Classifier::Load(), LasIOFilter::loadFile(), STEPFilter::loadFile(), CorePointDescSet::loadFromMSC(), DistanceMapGenerationDlg::loadOverlaySymbols(), new_image_char(), new_image_char_ini(), new_image_double(), new_image_double_ptr(), new_image_int(), new_ntuple_list(), nfa(), cloudViewer::t::io::RSBagReader::Open(), QuaGzipFile::open(), masc::NeighborhoodFeature::prepare(), masc::PointFeature::prepare(), pba::SparseBundleCPU< Float >::ProcessIndexCameraQ(), pba::SparseBundleCU::ProcessIndexCameraQ(), ReadCloud(), rect_nfa(), reduce_region_radius(), region_grow(), cloudViewer::CloudSamplingTools::resampleCloudSpatially(), cloudViewer::t::io::RealSenseSensor::ResumeRecord(), masc::PointFeature::retrieveField(), ri_del(), ri_end(), ri_inc(), ri_ini(), Classifier::save(), qCanupo2DViewDialog::saveClassifier(), PovFilter::saveToFile(), DRCFilter::saveToFile(), LasIOFilter::saveToFile(), cloudViewer::ManualSegmentationTools::segmentMeshWithAABox(), cloudViewer::ManualSegmentationTools::segmentMeshWithAAPlane(), cloudViewer::TrueKdTree::split(), cloudViewer::t::io::RealSenseSensor::StartCapture(), FastMarchingForFacetExtraction::step(), ThrowForFileError(), TileLasReader(), and QuaZIODevice::writeData().

◆ free_image_char()

static void free_image_char ( image_char  i)
static

Free memory used in image_char 'i'.

Definition at line 352 of file lsd.c.

References image_char_s::data, error(), and NULL.

◆ free_image_double()

static void free_image_double ( image_double  i)
static

Free memory used in image_double 'i'.

Definition at line 478 of file lsd.c.

References image_double_s::data, error(), and NULL.

◆ free_ntuple_list()

static void free_ntuple_list ( ntuple_list  in)
static

Free memory used in n-tuple 'in'.

Definition at line 249 of file lsd.c.

◆ gaussian_kernel()

static void gaussian_kernel ( ntuple_list  kernel,
double  sigma,
double  mean 
)
static

Compute a Gaussian kernel of length 'kernel->dim', standard deviation 'sigma', and centered at value 'mean'.

For example, if mean=0.5, the Gaussian will be centered in the middle point between values 'kernel->values[0]' and 'kernel->values[1]'.

Definition at line 548 of file lsd.c.

◆ gaussian_sampler()

static image_double gaussian_sampler ( image_double  in,
double  scale,
double  sigma_scale 
)
static

Scale the input image 'in' by a factor 'scale' by Gaussian sub-sampling.

For example, scale=0.8 will give a result at 80% of the original size.

The image is convolved with a Gaussian kernel

\[ G(x,y) = \frac{1}{2\pi\sigma^2} e^{-\frac{x^2+y^2}{2\sigma^2}} \]

before the sub-sampling to prevent aliasing.

The standard deviation sigma given by:

  • sigma = sigma_scale / scale, if scale < 1.0
  • sigma = sigma_scale, if scale >= 1.0

To be able to sub-sample at non-integer steps, some interpolation is needed. In this implementation, the interpolation is done by the Gaussian kernel, so both operations (filtering and sampling) are done at the same time. The Gaussian kernel is computed centered on the coordinates of the required sample. In this way, when applied, it gives directly the result of convolving the image with the kernel and interpolated to that particular position.

A fast algorithm is done using the separability of the Gaussian kernel. Applying the 2D Gaussian kernel is equivalent to applying first a horizontal 1D Gaussian kernel and then a vertical 1D Gaussian kernel (or the other way round). The reason is that

\[ G(x,y) = G(x) * G(y) \]

where

\[ G(x) = \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{x^2}{2\sigma^2}}. \]

The algorithm first applies a combined Gaussian kernel and sampling in the x axis, and then the combined Gaussian kernel and sampling in the y axis.

Definition at line 611 of file lsd.c.

◆ get_theta()

static double get_theta ( struct point reg,
int  reg_size,
double  x,
double  y,
image_double  modgrad,
double  reg_angle,
double  prec 
)
static

Compute region's angle as the principal inertia axis of the region.

The following is the region inertia matrix A:

\[ A = \left(\begin{array}{cc} Ixx & Ixy \\ Ixy & Iyy \\ \end{array}\right) \]

where

Ixx = sum_i G(i).(y_i - cx)^2

Iyy = sum_i G(i).(x_i - cy)^2

Ixy = - sum_i G(i).(x_i - cx).(y_i - cy)

and

  • G(i) is the gradient norm at pixel i, used as pixel's weight.
  • x_i and y_i are the coordinates of pixel i.
  • cx and cy are the coordinates of the center of th region.

lambda1 and lambda2 are the eigenvalues of matrix A, with lambda1 >= lambda2. They are found by solving the characteristic polynomial:

det( lambda I - A) = 0

that gives:

lambda1 = ( Ixx + Iyy + sqrt( (Ixx-Iyy)^2 + 4.0*Ixy*Ixy) ) / 2

lambda2 = ( Ixx + Iyy - sqrt( (Ixx-Iyy)^2 + 4.0*Ixy*Ixy) ) / 2

To get the line segment direction we want to get the angle the eigenvector associated to the smallest eigenvalue. We have to solve for a,b in:

a.Ixx + b.Ixy = a.lambda2

a.Ixy + b.Iyy = b.lambda2

We want the angle theta = atan(b/a). It can be computed with any of the two equations:

theta = atan( (lambda2-Ixx) / Ixy )

or

theta = atan( Ixy / (lambda2-Iyy) )

When |Ixx| > |Iyy| we use the first, otherwise the second (just to get better numeric precision).

Definition at line 1568 of file lsd.c.

References angle_diff(), image_double_s::data, double_equal(), error(), fabs(), M_PI, NULL, point::x, image_double_s::xsize, and point::y.

◆ inter_hi()

static double inter_hi ( double  x,
double  x1,
double  y1,
double  x2,
double  y2 
)
static

Interpolate y value corresponding to 'x' value given, in the line 'x1,y1' to 'x2,y2'; if 'x1=x2' return the larger of 'y1' and 'y2'.

The following restrictions are required:

  • x1 <= x2
  • x1 <= x
  • x <= x2

Definition at line 1299 of file lsd.c.

References double_equal(), and error().

Referenced by ri_inc().

◆ inter_low()

static double inter_low ( double  x,
double  x1,
double  y1,
double  x2,
double  y2 
)
static

Interpolate y value corresponding to 'x' value given, in the line 'x1,y1' to 'x2,y2'; if 'x1=x2' return the smaller of 'y1' and 'y2'.

The following restrictions are required:

  • x1 <= x2
  • x1 <= x
  • x <= x2

Definition at line 1277 of file lsd.c.

References double_equal(), and error().

Referenced by ri_inc().

◆ isaligned()

static int isaligned ( int  x,
int  y,
image_double  angles,
double  theta,
double  prec 
)
static

Is point (x,y) aligned to angle theta, up to precision 'prec'?

Definition at line 893 of file lsd.c.

References image_double_s::data, error(), FALSE, M_2__PI, M_3_2_PI, NOTDEF, NULL, coorlist::x, image_double_s::xsize, coorlist::y, and image_double_s::ysize.

Referenced by rect_nfa(), and region_grow().

◆ LineSegmentDetection()

double* LineSegmentDetection ( int *  n_out,
double *  img,
int  X,
int  Y,
double  scale,
double  sigma_scale,
double  quant,
double  ang_th,
double  log_eps,
double  density_th,
int  n_bins,
int **  reg_img,
int *  reg_x,
int *  reg_y 
)

LSD full interface.

Definition at line 2025 of file lsd.c.

References image.

Referenced by lsd_scale_region().

◆ ll_angle()

static image_double ll_angle ( image_double  in,
double  threshold,
struct coorlist **  list_p,
void **  mem_p,
image_double modgrad,
unsigned int  n_bins 
)
static

Computes the direction of the level line of 'in' at each point.

The result is:

  • an image_double with the angle at each pixel, or NOTDEF if not defined.
  • the image_double 'modgrad' (a pointer is passed as argument) with the gradient magnitude at each point.
  • a list of pixels 'list_p' roughly ordered by decreasing gradient magnitude. (The order is made by classifying points into bins by gradient magnitude. The parameters 'n_bins' and 'max_grad' specify the number of bins and the gradient modulus at the highest bin. The pixels in the list would be in decreasing gradient magnitude, up to a precision of the size of the bins.)
  • a pointer 'mem_p' to the memory used by 'list_p' to be able to free the memory when it is not used anymore.

Definition at line 752 of file lsd.c.

◆ log_gamma_lanczos()

static double log_gamma_lanczos ( double  x)
static

Computes the natural logarithm of the absolute value of the gamma function of x using the Lanczos approximation. See http://www.rskey.org/gamma.htm

The formula used is

\[ \Gamma(x) = \frac{ \sum_{n=0}^{N} q_n x^n }{ \Pi_{n=0}^{N} (x+n) } (x+5.5)^{x+0.5} e^{-(x+5.5)} \]

so

\[ \log\Gamma(x) = \log\left( \sum_{n=0}^{N} q_n x^n \right) + (x+0.5) \log(x+5.5) - (x+5.5) - \sum_{n=0}^{N} \log(x+n) \]

and q0 = 75122.6331530, q1 = 80916.6278952, q2 = 36308.2951477, q3 = 8687.24529705, q4 = 1168.92649479, q5 = 83.8676043424, q6 = 2.50662827511.

Definition at line 980 of file lsd.c.

References coorlist::x.

◆ log_gamma_windschitl()

static double log_gamma_windschitl ( double  x)
static

Computes the natural logarithm of the absolute value of the gamma function of x using Windschitl method. See http://www.rskey.org/gamma.htm

The formula used is

\[ \Gamma(x) = \sqrt{\frac{2\pi}{x}} \left( \frac{x}{e} \sqrt{ x\sinh(1/x) + \frac{1}{810x^6} } \right)^x \]

so

\[ \log\Gamma(x) = 0.5\log(2\pi) + (x-0.5)\log(x) - x + 0.5x\log\left( x\sinh(1/x) + \frac{1}{810x^6} \right). \]

This formula is a good approximation when x > 15.

Definition at line 1014 of file lsd.c.

References coorlist::x.

◆ lsd()

double* lsd ( int *  n_out,
double *  img,
int  X,
int  Y 
)

LSD Simple Interface.

Definition at line 2243 of file lsd.c.

References lsd_scale(), and X.

◆ lsd_scale()

double* lsd_scale ( int *  n_out,
double *  img,
int  X,
int  Y,
double  scale 
)

LSD Simple Interface with Scale.

Definition at line 2235 of file lsd.c.

References lsd_scale_region(), NULL, and X.

Referenced by lsd().

◆ lsd_scale_region()

double* lsd_scale_region ( int *  n_out,
double *  img,
int  X,
int  Y,
double  scale,
int **  reg_img,
int *  reg_x,
int *  reg_y 
)

LSD Simple Interface with Scale and Region output.

Definition at line 2212 of file lsd.c.

References LineSegmentDetection(), G3Point::quant(), and X.

Referenced by lsd_scale().

◆ new_image_char()

static image_char new_image_char ( unsigned int  xsize,
unsigned int  ysize 
)
static

Create a new image_char of size 'xsize' times 'ysize'.

Definition at line 363 of file lsd.c.

References error(), image, and NULL.

Referenced by new_image_char_ini().

◆ new_image_char_ini()

static image_char new_image_char_ini ( unsigned int  xsize,
unsigned int  ysize,
unsigned char  fill_value 
)
static

Create a new image_char of size 'xsize' times 'ysize', initialized to the value 'fill_value'.

Definition at line 388 of file lsd.c.

References error(), image, new_image_char(), and NULL.

◆ new_image_double()

static image_double new_image_double ( unsigned int  xsize,
unsigned int  ysize 
)
static

Create a new image_double of size 'xsize' times 'ysize'.

Definition at line 489 of file lsd.c.

References error(), image, and NULL.

◆ new_image_double_ptr()

static image_double new_image_double_ptr ( unsigned int  xsize,
unsigned int  ysize,
double *  data 
)
static

Create a new image_double of size 'xsize' times 'ysize' with the data pointed by 'data'.

Definition at line 513 of file lsd.c.

References error(), image, and NULL.

◆ new_image_int()

static image_int new_image_int ( unsigned int  xsize,
unsigned int  ysize 
)
static

Create a new image_int of size 'xsize' times 'ysize'.

Definition at line 423 of file lsd.c.

References error(), image, and NULL.

Referenced by new_image_int_ini().

◆ new_image_int_ini()

static image_int new_image_int_ini ( unsigned int  xsize,
unsigned int  ysize,
int  fill_value 
)
static

Create a new image_int of size 'xsize' times 'ysize', initialized to the value 'fill_value'.

Definition at line 447 of file lsd.c.

References image, and new_image_int().

◆ new_ntuple_list()

static ntuple_list new_ntuple_list ( unsigned int  dim)
static

Create an n-tuple list and allocate memory for one element.

Parameters
dimthe dimension (n) of the n-tuple.

Definition at line 261 of file lsd.c.

References ntuple_list_s::dim, error(), ntuple_list_s::max_size, NULL, ntuple_list_s::size, and ntuple_list_s::values.

◆ nfa()

static double nfa ( int  n,
int  k,
double  p,
double  logNT 
)
static

Computes -log10(NFA).

NFA stands for Number of False Alarms:

\[ \mathrm{NFA} = NT \cdot B(n,k,p) \]

  • NT - number of tests
  • B(n,k,p) - tail of binomial distribution with parameters n,k and p:

    \[ B(n,k,p) = \sum_{j=k}^n \left(\begin{array}{c}n\\j\end{array}\right) p^{j} (1-p)^{n-j} \]

The value -log10(NFA) is equivalent but more intuitive than NFA:

  • -1 corresponds to 10 mean false alarms
  • 0 corresponds to 1 mean false alarm
  • 1 corresponds to 0.1 mean false alarms
  • 2 corresponds to 0.01 mean false alarms
  • ...

Used this way, the bigger the value, better the detection, and a logarithmic scale is used.

Parameters
n,k,pbinomial parameters.
logNTlogarithm of Number of Tests

The computation is based in the gamma function by the following relation:

\[ \left(\begin{array}{c}n\\k\end{array}\right) = \frac{ \Gamma(n+1) }{ \Gamma(k+1) \cdot \Gamma(n-k+1) }. \]

We use efficient algorithms to compute the logarithm of the gamma function.

To make the computation faster, not all the sum is computed, part of the terms are neglected based on a bound to the error obtained (an error of 10% in the result is accepted).

Definition at line 1074 of file lsd.c.

References double_equal(), error(), fabs(), log_gamma, M_LN10, and TABSIZE.

Referenced by rect_nfa().

◆ rect_copy()

static void rect_copy ( struct rect in,
struct rect out 
)
static

Copy one rectangle structure to another.

Definition at line 1183 of file lsd.c.

Referenced by rect_improve().

◆ rect_improve()

static double rect_improve ( struct rect rec,
image_double  angles,
double  logNT,
double  log_eps 
)
static

Try some rectangles variations to improve NFA value. Only if the rectangle is not meaningful (i.e., log_nfa <= log_eps).

Definition at line 1756 of file lsd.c.

References rect::dx, rect::dy, M_PI, rect::p, rect::prec, rect_copy(), rect_nfa(), rect::width, rect::x1, rect::x2, rect::y1, and rect::y2.

◆ rect_nfa()

static double rect_nfa ( struct rect rec,
image_double  angles,
double  logNT 
)
static

Compute a rectangle's NFA value.

Definition at line 1482 of file lsd.c.

References error(), isaligned(), nfa(), NULL, rect::p, rect::prec, ri_del(), ri_end(), ri_inc(), ri_ini(), rect::theta, rect_iter::x, image_double_s::xsize, rect_iter::y, and image_double_s::ysize.

Referenced by rect_improve().

◆ reduce_region_radius()

static int reduce_region_radius ( struct point reg,
int *  reg_size,
image_double  modgrad,
double  reg_angle,
double  prec,
double  p,
struct rect rec,
image_char  used,
image_double  angles,
double  density_th 
)
static

Reduce the region size, by elimination the points far from the starting point, until that leads to rectangle with the right density of region points or to discard the region if too small.

Definition at line 1869 of file lsd.c.

References image_char_s::data, image_double_s::data, dist(), error(), FALSE, NOTUSED, NULL, rect::p, rect::prec, region2rect(), TRUE, rect::width, point::x, rect::x, rect::x1, rect::x2, image_char_s::xsize, point::y, rect::y, rect::y1, and rect::y2.

◆ refine()

static int refine ( struct point reg,
int *  reg_size,
image_double  modgrad,
double  reg_angle,
double  prec,
double  p,
struct rect rec,
image_char  used,
image_double  angles,
double  density_th 
)
static

Refine a rectangle.

For that, an estimation of the angle tolerance is performed by the standard deviation of the angle at points near the region's starting point. Then, a new region is grown starting from the same point, but using the estimated angle tolerance. If this fails to produce a rectangle with the right density of region points, 'reduce_region_radius' is called to try to satisfy this condition.

Definition at line 1947 of file lsd.c.

◆ region2rect()

static void region2rect ( struct point reg,
int  reg_size,
image_double  modgrad,
double  reg_angle,
double  prec,
double  p,
struct rect rec 
)
static

Computes a rectangle that covers a region of points.

Definition at line 1611 of file lsd.c.

Referenced by reduce_region_radius().

◆ region_grow()

static void region_grow ( int  x,
int  y,
image_double  angles,
struct point reg,
int *  reg_size,
double *  reg_angle,
image_char  used,
double  prec 
)
static

Build a region of pixels that share the same angle, up to a tolerance 'prec', starting at point (x,y).

Definition at line 1704 of file lsd.c.

References image_char_s::data, image_double_s::data, error(), isaligned(), NULL, USED, point::x, image_char_s::xsize, image_double_s::xsize, point::y, image_char_s::ysize, and image_double_s::ysize.

◆ ri_del()

static void ri_del ( rect_iter iter)
static

Free memory used by a rectangle iterator.

Definition at line 1314 of file lsd.c.

References error(), and NULL.

Referenced by rect_nfa().

◆ ri_end()

static int ri_end ( rect_iter i)
static

Check if the iterator finished the full iteration.

See details in rect_iter

Definition at line 1325 of file lsd.c.

References error(), NULL, rect_iter::vx, and rect_iter::x.

Referenced by rect_nfa(), and ri_inc().

◆ ri_inc()

static void ri_inc ( rect_iter i)
static

Increment a rectangle iterator.

See details in rect_iter

Definition at line 1341 of file lsd.c.

References cloudViewer::utility::ceil(), error(), inter_hi(), inter_low(), NULL, ri_end(), rect_iter::vx, rect_iter::vy, rect_iter::x, rect_iter::y, rect_iter::ye, and rect_iter::ys.

Referenced by rect_nfa(), and ri_ini().

◆ ri_ini()

static rect_iter* ri_ini ( struct rect r)
static

Create and initialize a rectangle iterator.

See details in rect_iter

Definition at line 1411 of file lsd.c.

References cloudViewer::utility::ceil(), rect::dx, rect::dy, error(), NULL, offset, ri_inc(), rect_iter::vx, rect_iter::vy, rect::width, rect_iter::x, rect::x1, rect::x2, rect_iter::y, rect::y1, rect::y2, rect_iter::ye, and rect_iter::ys.

Referenced by rect_nfa().