Skip to content

lines_gaussLinesGaussLinesGausslines_gausslines_gauss๐Ÿ”—

Short description๐Ÿ”—

lines_gaussLinesGaussLinesGausslines_gausslines_gauss โ€” Detect lines and their width.

Signature๐Ÿ”—

lines_gauss( image Image, out xld_cont Lines, number Sigma, number Low, number High, string LightDark, string ExtractWidth, string LineModel, string CompleteJunctions )void LinesGauss( const HObject& Image, HObject* Lines, const HTuple& Sigma, const HTuple& Low, const HTuple& High, const HTuple& LightDark, const HTuple& ExtractWidth, const HTuple& LineModel, const HTuple& CompleteJunctions )static void HOperatorSet.LinesGauss( HObject image, out HObject lines, HTuple sigma, HTuple low, HTuple high, HTuple lightDark, HTuple extractWidth, HTuple lineModel, HTuple completeJunctions )def lines_gauss( image: HObject, sigma: Union[float, int], low: Union[float, int], high: Union[float, int], light_dark: str, extract_width: str, line_model: str, complete_junctions: str ) -> HObject

Herror lines_gauss( const Hobject Image, Hobject* Lines, double Sigma, double Low, double High, const char* LightDark, const char* ExtractWidth, const char* LineModel, const char* CompleteJunctions )

Herror T_lines_gauss( const Hobject Image, Hobject* Lines, const Htuple Sigma, const Htuple Low, const Htuple High, const Htuple LightDark, const Htuple ExtractWidth, const Htuple LineModel, const Htuple CompleteJunctions )

HXLDCont HImage::LinesGauss( const HTuple& Sigma, const HTuple& Low, const HTuple& High, const HString& LightDark, const HString& ExtractWidth, const HString& LineModel, const HString& CompleteJunctions ) const

HXLDCont HImage::LinesGauss( double Sigma, double Low, double High, const HString& LightDark, const HString& ExtractWidth, const HString& LineModel, const HString& CompleteJunctions ) const

HXLDCont HImage::LinesGauss( double Sigma, double Low, double High, const char* LightDark, const char* ExtractWidth, const char* LineModel, const char* CompleteJunctions ) const

HXLDCont HImage::LinesGauss( double Sigma, double Low, double High, const wchar_t* LightDark, const wchar_t* ExtractWidth, const wchar_t* LineModel, const wchar_t* CompleteJunctions ) const (Windows only)

HXLDCont HImage.LinesGauss( HTuple sigma, HTuple low, HTuple high, string lightDark, string extractWidth, string lineModel, string completeJunctions )

HXLDCont HImage.LinesGauss( double sigma, double low, double high, string lightDark, string extractWidth, string lineModel, string completeJunctions )

Description๐Ÿ”—

The operator lines_gaussLinesGauss can be used to extract lines (curvilinear structures) from the image Imageimageimage. The extracted lines are returned in Lineslineslines as subpixel precise XLD-contours.

The parameter LightDarklightDarklight_dark determines, whether bright ('light'"light") or dark ('dark'"dark") lines are extracted.

If ExtractWidthextractWidthextract_width is set to 'true'"true" the line width is extracted for each line point.

LineModellineModelline_model determines if and how the position and width of asymmetric lines (lines having different contrast on each side of the line) should be compensated. The following values can be set for LineModellineModelline_model:

  • 'bar-shaped'"bar-shaped": Bar-shaped line model. Covers most use cases.

  • 'parabolic'"parabolic": Parabolic line model. Can be used for the extraction of backlit tubular objects (e.g., blood vessels in X-ray images) where the lines appear very sharp.

  • 'gaussian'"gaussian": Gaussian line model. Can be used for the extraction of backlit tubular objects (e.g., blood vessels in X-ray images) where the lines appear less sharp.

  • 'none'"none": The effects of asymmetric lines are not compensated.

The parameter LineModellineModelline_model is only effective if ExtractWidthextractWidthextract_width='true'"true".

Because the line extractor is unable to extract certain junctions because of differential geometric reasons, it tries to extract these by different means if CompleteJunctionscompleteJunctionscomplete_junctions is set to 'true'"true".

The extraction is done by using partial derivatives of a Gaussian smoothing kernel to determine the parameters of a quadratic polynomial in x and y for each point of the image. The parameter Sigmasigmasigma determines the amount of smoothing to be performed. Larger values of Sigmasigmasigma lead to a larger smoothing of the image, but can lead to worse localization of the line. Generally, the localization will be much better than that of lines returned by lines_facetLinesFacet with comparable parameters. The parameters of the polynomial are used to calculate the line direction for each pixel. Pixels which exhibit a local maximum in the second directional derivative perpendicular to the line direction are marked as line points. The line points found in this manner are then linked to contours. This is done by immediately accepting line points that have a second derivative larger than Highhighhigh. Points that have a second derivative smaller than Lowlowlow are rejected. All other line points are accepted if they are connected to accepted points by a connected path. This is similar to a hysteresis threshold operation with infinite path length (see hysteresis_thresholdHysteresisThreshold), here, however contours are extracted with subpixel precision.

For the choice of the thresholds Highhighhigh and Lowlowlow one has to keep in mind that the second directional derivative depends on the amplitude and width of the line as well as the choice of Sigmasigmasigma. The value of the second derivative depends linearly on the amplitude, i.e., the larger the amplitude, the larger the response. For the width of the line there is an approximately inverse exponential dependence: The wider the line is, the smaller the response gets. This holds analogously for the dependence on Sigmasigmasigma: The larger Sigmasigmasigma is chosen, the smaller the second derivative will be. This means that for larger smoothing correspondingly smaller values for Highhighhigh and Lowlowlow have to be chosen. Two examples help to illustrate this: If 5 pixel wide lines with an amplitude larger than 100 are to be extracted from an image with a smoothing of Sigmasigmasigma = 1.5, Highhighhigh should be chosen larger than 14. If, on the other hand, 10 pixel wide lines with an amplitude larger than 100 and a Sigmasigmasigma = 3 are to be detected, Highhighhigh should be chosen larger than 3.5. For the choice of Lowlowlow values between 0.25 Highhighhigh and 0.5 Highhighhigh are appropriate.

The parameters Lowlowlow and Highhighhigh can be calculated from the respective gray value contrast of the lines to be extracted (\(ContrastLow\) and \(ContrastHigh\)) and from the chosen value for Sigmasigmasigma with the following formula:

\[\begin{eqnarray*} { \textrm{Low} \choose \textrm{High} } = \left| -2 \cdot { ContrastLow \choose ContrastHigh } \cdot \frac{w}{\sqrt{2 \pi} \cdot \textrm{Sigma}^{3}} \cdot e^{-\frac{w^2}{2 \cdot \textrm{Sigma}^2}} \right| \end{eqnarray*}\]

where \(w\) is the width (half the diameter) of the lines in the image. \(ContrastLow\) and \(ContrastHigh\) determine the gray value range the lines are expected to differ from the background. Suitable values for Lowlowlow and Highhighhigh can be calculated using the procedure calculate_lines_gauss_parameters.

The extracted lines are returned in a topologically sound data structure in Lineslineslines. This means that lines are correctly split at junction points.

lines_gaussLinesGauss defines the following attributes for each line point if ExtractWidthextractWidthextract_width was set to 'false'"false":

  • 'angle'"angle": The angle of the direction perpendicular to the line

  • 'response'"response": The magnitude of the second derivative

If ExtractWidthextractWidthextract_width was set to 'true'"true", the following attributes are defined in addition to 'angle'"angle" and 'response'"response":

  • 'width_left'"width_left": The line width to the left of the line

  • 'width_right'"width_right": The line width to the right of the line

If ExtractWidthextractWidthextract_width was set to 'true'"true" and LineModellineModelline_model to a value different from 'none'"none", the following attributes are defined in addition to 'angle'"angle", 'response'"response", 'width_left'"width_left", and 'width_right'"width_right":

  • 'asymmetry'"asymmetry": The asymmetry of the line point

  • 'contrast'"contrast": The contrast of the line point

Here, the asymmetry is positive if the asymmetric part, i.e., the part with the weaker gradient, is on the right side of the line, while it is negative if the asymmetric part is on the left side of the line.

The contrast results from the difference between the gray value of the line and the gray value of the background. The contrast is positive if bright lines are extracted, while it is negative if dark lines are extracted. The returned contrast may be larger than the maximum gray value the input image type is able to represent, especially if the line model specified by LineModellineModelline_model is not present in the image. For example, for byte images, the contrast may be greater than 255.

Use get_contour_attrib_xldGetContourAttribXld to obtain attribute values. See the operator reference of get_contour_attrib_xldGetContourAttribXld for further information about contour attributes.

lines_gaussLinesGauss can be executed on OpenCL devices.

Attention๐Ÿ”—

In general, but in particular if the line width is to be extracted, \(\textrm{Sigma} \ge w/\sqrt{3}\) should be selected, where \(w\) is the width (half the diameter) of the lines in the image. As the lowest allowable value \(\textrm{Sigma} \ge w/2.5\) must be selected. If, for example, lines with a width of 4 pixels (diameter 8 pixels) are to be extracted, \(\textrm{Sigma} \ge 2.3\) should be selected. Note that the attributes 'width_left'"width_left", 'width_right'"width_right", 'asymmetry'"asymmetry", and 'contrast'"contrast" are set to zero if Sigmasigmasigma is set too low.

lines_gaussLinesGauss uses a special implementation that is optimized using SSE2 or AVX2 instructions, if the system parameters 'sse2_enable'"sse2_enable" or 'avx2_enable'"avx2_enable" are set to 'true'"true" (see set_systemSetSystem). These implementations are slightly inaccurate compared to the pure C version due to numerical issues. If you prefer accuracy over performance you can set the respective system parameter to 'false'"false" (using set_systemSetSystem) before you call lines_gaussLinesGauss. This way lines_gaussLinesGauss does not use SSE2 or AVX2 accelerations. Donโ€™t forget to set 'sse2_enable'"sse2_enable" or 'avx2_enable'"avx2_enable" back to 'true'"true" afterwards.

When lines_gaussLinesGauss is run on OpenCL devices, the same limitations apply as for derivate_gaussDerivateGauss: Sigmasigmasigma must be chosen so that the required filter mask is smaller than 129 pixels. Also note that the results can vary compared to the CPU implementation.

Note that filter operators may return unexpected results if an image with a reduced domain is used as input. Please refer to the chapter Filters.

Execution information๐Ÿ”—

Execution information
  • Supports OpenCL compute devices.

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on internal data level.

This operator supports canceling timeouts and interrupts.

Parameters๐Ÿ”—

Imageimageimage (input_object) singlechannelimage โ†’ object (byte / int1 / int2 / uint2 / int4 / real)HObject (byte / int1 / int2 / uint2 / int4 / real)HImage (byte / int1 / int2 / uint2 / int4 / real)HObject (byte / int1 / int2 / uint2 / int4 / real)Hobject (byte / int1 / int2 / uint2 / int4 / real)

Input image.

Lineslineslines (output_object) xld_cont-array โ†’ objectHObjectHXLDContHObjectHobject *

Extracted lines.

Sigmasigmasigma (input_control) number โ†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[float, int]Htuple (double / Hlong)

Amount of Gaussian smoothing to be applied.

Default: 1.51.5
Suggested values: 1, 1.2, 1.5, 1.8, 2, 2.5, 3, 4, 51, 1.2, 1.5, 1.8, 2, 2.5, 3, 4, 5
Value range: 0 โ‰ค Sigma
Recommended increment: 0.1

Lowlowlow (input_control) number โ†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[float, int]Htuple (double / Hlong)

Lower threshold for the hysteresis threshold operation.

Default: 33
Suggested values: 0, 0.5, 1, 2, 3, 4, 5, 8, 100, 0.5, 1, 2, 3, 4, 5, 8, 10
Value range: 0 โ‰ค Low
Recommended increment: 0.5

Highhighhigh (input_control) number โ†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[float, int]Htuple (double / Hlong)

Upper threshold for the hysteresis threshold operation.

Default: 88
Suggested values: 0, 0.5, 1, 2, 3, 4, 5, 8, 10, 12, 15, 18, 20, 250, 0.5, 1, 2, 3, 4, 5, 8, 10, 12, 15, 18, 20, 25
Value range: 0 โ‰ค High
Recommended increment: 0.5
Restriction: High >= Low

LightDarklightDarklight_dark (input_control) string โ†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Extract bright or dark lines.

Default: 'light'"light"
List of values: 'dark', 'light'"dark", "light"

ExtractWidthextractWidthextract_width (input_control) string โ†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Should the line width be extracted?

Default: 'true'"true"
List of values: 'false', 'true'"false", "true"

LineModellineModelline_model (input_control) string โ†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Line model used to correct the line position and width.

Default: 'bar-shaped'"bar-shaped"
List of values: 'bar-shaped', 'gaussian', 'none', 'parabolic'"bar-shaped", "gaussian", "none", "parabolic"

CompleteJunctionscompleteJunctionscomplete_junctions (input_control) string โ†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Should junctions be added where they cannot be extracted?

Default: 'true'"true"
List of values: 'false', 'true'"false", "true"

Example๐Ÿ”—

(HDevelop)


* Detection of lines in an aerial image
read_image(Image,'mreut4_3')
lines_gauss(Image,Lines,1.5,3,8,'light','true','bar-shaped','true')
dev_display(Lines)
(C)
/* Detection of lines in an aerial image */
read_image(&Image,"mreut4_3")\;
lines_gauss(Image:&Lines:1.5,3,8,"light","true","bar-shaped","true")\;
disp_xld(Lines,WindowHandle)\;
(C++)
/* Detection of lines in an aerial image */
HWindow w(0,0,520,560)\;
HImage Image("mreut4_3")\;
HXLDContArray Lines = Image.LinesGauss(1.5,3,8,"light","true",
                                       "bar-shaped","true")\;
Lines.Display(w)\;

Complexity๐Ÿ”—

Let \(A\) be the number of pixels in the domain of Imageimageimage. Then the runtime complexity is \(O(A*\textrm{Sigma})\).

The amount of temporary memory required is dependent on the height \(H\) of the domain of Imageimageimage and the width \(W\) of Imageimageimage. Let \(S = W*H\), then lines_gaussLinesGauss requires at least \(55*S\) bytes of temporary memory during execution.

Result๐Ÿ”—

lines_gaussLinesGauss returns 2 (H_MSG_TRUE) if all parameters are correct and no error occurs during execution. If the input is empty the behavior can be set via set_system(::'no_object_result',<Result>:). If necessary, an exception is raised.

Combinations with other operators๐Ÿ”—

Combinations

Possible successors

gen_polygons_xldGenPolygonsXld

Alternatives

lines_facetLinesFacet

See also

bandpass_imageBandpassImage, dyn_thresholdDynThreshold, topographic_sketchTopographicSketch

References๐Ÿ”—

C. Steger: Extracting Curvilinear Structures: A Differential Geometric Approach''. In B. Buxton, R. Cipolla, eds.,Fourth European Conference on Computer Visionโ€™โ€˜, Lecture Notes in Computer Science, Volume 1064, Springer Verlag, pp. 630-641, 1996.

C. Steger: โ€œExtraction of Curved Lines from Imagesโ€. In ``13th International Conference on Pattern Recognitionโ€™โ€˜, Volume II, pp. 251-255, 1996.

C. Steger: โ€œAn Unbiased Detector of Curvilinear Structuresโ€. IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 20, no. 2, pp. 113-125, 1998.

C. Steger: ``Unbiased extraction of lines with parabolic and Gaussian profilesโ€™โ€˜. Computer Vision and Image Understanding, vol. 117, no. 2, pp. 97-112, 2013.

Module๐Ÿ”—

2D Metrology