ImageLines[image]
finds line segments in image and returns the coordinates of their endpoints.
ImageLines[image,t]
uses the threshold t for selecting image lines.
ImageLines[image,t,d]
uses the parameter d to control the distinctness of the detected lines.
ImageLines[video,…]
finds lines in frames of video.
ImageLines
ImageLines[image]
finds line segments in image and returns the coordinates of their endpoints.
ImageLines[image,t]
uses the threshold t for selecting image lines.
ImageLines[image,t,d]
uses the parameter d to control the distinctness of the detected lines.
ImageLines[video,…]
finds lines in frames of video.
Details and Options
- ImageLines returns a list of line segments in the form Line[{p1,p2}], where each pi={xi,yi} is expressed in the standard image coordinate system.
- ImageLines[image,t] finds lines in the image whose normalized strength is larger than the specified threshold t.
- ImageLines sorts the result based on the normalized strength.
- In ImageLines[image,t,d], the parameter d controls how close lines are suppressed. If the value is set to zero, all detected lines are returned. With d set to 1, only the strongest line may be returned.
- The following options can be given:
-
MaxFeatures All maximum number of features to return Method "Hough" method to detect lines - With a setting MaxFeatures->n, at most n lines with largest normalized strength are returned.
- Possible line detection methods are:
-
"Hough" lines based on Hough transform (default) "RANSAC" lines using the RANSAC algorithm - With Method->"Hough", lines are detected by iteratively selecting the strongest peaks in the Hough transform. Using the distinctness parameter, peaks that are within a rectangular range from the already selected peaks are excluded from the set of line candidates.
- With Method->"RANSAC", lines are detected using random sampling. For each sampling, pixels that are within a distance specified by the distinctness parameter d are used for computing the strength of the line. The pixels on the selected line are not used in the following iterations.
- By default, ImageLines returns lines that span from border to border. With a setting Method->{"Segmented"->True}, detected lines may be divided into smaller line segments.
Examples
open all close allBasic Examples (1)
Scope (2)
Options (3)
MaxFeatures (1)
Method (2)
By default, lines are detected using Method->"Hough":
img = [image];
lines = ImageLines[img, .23, Method -> "Hough"];
HighlightImage[img, lines]lines = ImageLines[img, .23, Method -> "RANSAC"];
HighlightImage[img, lines]Detect segmented lines in a grayscale image:
img = [image];
lines = ImageLines[img, .2, Method -> {"Hough", "Segmented" -> True}];
HighlightImage[img, lines, ImageSize -> 240]Segmented lines using the random sampling method:
lines = ImageLines[img, .23, Method -> {"RANSAC", "Segmented" -> True}];HighlightImage[img, lines, ImageSize -> 240]Applications (6)
Detect and visualize straight trajectories in a bubble chamber image:
img = [image];
lines = ImageLines[img];
HighlightImage[img, lines]Detect segments on a color image:
img = [image];
lines = ImageLines[img, .53, .03, Method -> {"Segmented" -> True}];
HighlightImage[img, {Black, lines}, ImageSize -> 320]img = [image];
lines = ImageLines[EdgeDetect[img], .28, .06];
HighlightImage[img, lines]Detect segments on a gradient magnitude map:
img = [image];
lines = ImageLines[ImageAdjust@GradientFilter[img, 3, Method -> {"NonMaxSuppression" -> True}], .09, Method -> {"Segmented" -> True}];
HighlightImage[img, {Yellow, lines}]Find wide lines using edge detection:
img = [image];
lines = ImageLines[EdgeDetect[img, 13], .18];
HighlightImage[img, lines]image = [image];Compute the gradient of the image to highlight edges:
(g = GradientFilter[image, 2])//ImageAdjustFind the most significant straight lines in the gradient image:
HighlightImage[image, lines = ImageLines[g, MaxFeatures -> 10]]FInd the angles corresponding to each line:
angles = Mod[ArcTan@@@Flatten[Differences@@@lines, 1], π]Compute the average angle of the vertical lines:
θ = Mean@Select[angles, Abs[# - π / 2] < π / 4&]Rotate the image by
to make almost-vertical lines vertical:
ImageRotate[image, π / 2 - θ]Possible Issues (2)
Use the distinctness parameter to prevent detecting duplicated lines:
Length@ImageLines[[image], .1, #]& /@ {0, .1}Thin lines in binary images might not be correctly detected:
i = [image];lines = ImageLines[i, MaxFeatures -> 3, Method -> {"Segmented" -> True}];
HighlightImage[i, lines]Blurring the image typically improves line detection:
lines = ImageLines[Blur[i], MaxFeatures -> 3, Method -> {"Segmented" -> True}];
HighlightImage[i, lines]Rescaling the image to a larger size might also help in some cases:
i2 = ImageResize[i, Scaled[2]];lines = ImageLines[i2, MaxFeatures -> 3, Method -> {"Segmented" -> True}];
HighlightImage[i2, lines]History
Introduced in 2010 (8.0) | Updated in 2012 (9.0) ▪ 2014 (10.0) ▪ 2018 (11.3) ▪ 2025 (14.2)
Text
Wolfram Research (2010), ImageLines, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageLines.html (updated 2025).
CMS
Wolfram Language. 2010. "ImageLines." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/ImageLines.html.
APA
Wolfram Language. (2010). ImageLines. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImageLines.html
BibTeX
@misc{reference.wolfram_2026_imagelines, author="Wolfram Research", title="{ImageLines}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/ImageLines.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_imagelines, organization={Wolfram Research}, title={ImageLines}, year={2025}, url={https://reference.wolfram.com/language/ref/ImageLines.html}, note=[Accessed: 13-June-2026]}