# Find a specific line in a picture

I want to find the line between color blue and color gray in the following picture:

More exactly, the end points of that line.

Is the Hough transform a choice? If yes how should I set up the picture before using Hough?

Any way of solving this would be helpful.

• Do an edge detection before Hough transform. It will turn that transition into a bright line with black on both sides – endolith Jan 6 '12 at 15:18

## 2 Answers

In general, you want an edge detector, like the Canny edge detector, for this kind of problem. The Hough transform is useful for extracting lines rather than edges.

However, in this specific case, you're better off doing something like:

imdata = imread('grayblue.jpg');
colidx = find(diff(imdata(1,:) ~= 0);


since it's such a simple image.

For an image this simple a convolution kernel like the following will find edges nicely:

[-1 2 - 1]

This yields a single edge pixel at each edge point. No fuss, no muss. Canny is too involved for this problem. If you want to find edge points for lines at any angle, then you can use a simple Laplacian, Laplacian of Gaussian (LoG), or Difference of Gaussian (DoG). Sobel and Prewitt are also simple but inappropriate since they yield a "double thickness" line.

There's a wicked fast implementation of Hough described here: http://www.ic.uff.br/~laffernandes/projects/kht/index.html

There are also "parameterless Hough" algorithms that are very fast, but a bit tricky to implement and debug.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5604776740074158, "perplexity": 1471.7059125959488}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-05/segments/1579251773463.72/warc/CC-MAIN-20200128030221-20200128060221-00407.warc.gz"}