3

Does anybody have an idea on how I can create shapes from Canny Edge Detection in Canvas?

hippietrail
17.3k21 gold badges114 silver badges181 bronze badges
asked Oct 7, 2013 at 8:32

2 Answers 2

4

I assume here you already have the Canny edge detection implemented based on the way the question is formulated -

You can use an approach such as this (written in Java but should be easy enough to translate into JavaScript) and/or perhaps some limited use of line-fitting approaches (statistical).

The essence is that you will have to find out which pixels are connected and create polygon objects/arrays yourselves based on the result of the edge detection.

Once you have the connected pixels you can use point reduction algorithms such as the Ramer–Douglas–Peucker algorithm (JavaScript implementation here) to avoid the polygons to contain every single point of similar sloped lines and so forth.

You will run into a variety of challenges though such as short segmented lines due to too much noise in the original image or "weak lines", clusters of "lines" which makes it hard to find out how to connect them as polygons.

answered Oct 7, 2013 at 8:55
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know of any libraries for this, however you could:

  • Use getImageData() to access a byte[] of pixel data
  • Implement your own convolution filter on top of that data (examples for this may exist online)

In this way you can find areas of high contrast (edges.)

EDIT I agree with Ken -- I may have misread the question.

In addition to Ken's answer, if you know what kinds of shapes you're looking for then you might like to look at the Hough Transform which is well suited to detecting lines, ellipses and other shapes that can be geometrically defined using only a few parameters.

answered Oct 7, 2013 at 8:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.