Canny edge and now? Edge extraction - anyone?!

For everything that's not in any way related to PureBasic. General chat etc...
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Canny edge and now? Edge extraction - anyone?!

Post by DarkDragon »

Hello,

I need to find an algorithm for exact edge extraction from a canny edge result. I tried the hough transformation and the probabilistic hough transformation, but no one of them is generating good results. They either produce too much lines for one place or weird non existing lines in the middle of noisy areas and both are not reproducing all edges.

Can anyone tell me a better vectorizing algorithm for lines? I only know a good one for areas.
bye,
Daniel
User avatar
codewalker
Enthusiast
Enthusiast
Posts: 331
Joined: Mon Mar 27, 2006 2:08 pm
Location: Spain

Re: Canny edge and now? Edge extraction - anyone?!

Post by codewalker »

dude, you're blowing my mind :shock:
There is a difference between knowing the code and writing the code.
May the code be strong in your projects.
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Canny edge and now? Edge extraction - anyone?!

Post by gnasen »

i already worked on the same problem and couldn't find a satisfying algorithm. I didn't try it yet, but you could use the "harris corner detector" to get the most important corners in your picture. If an edge is matching at least two corners, its a good edge. At this way you can maybe get rid of "bad" edges.

You could also try to use another convolution (I used sober instead of candy).
pb 5.11
Zach
Addict
Addict
Posts: 1676
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Canny edge and now? Edge extraction - anyone?!

Post by Zach »

codewalker wrote:dude, you're blowing my mind :shock:
QFT :|
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Canny edge and now? Edge extraction - anyone?!

Post by DarkDragon »

First of all: thanks for your answer gnasen.
gnasen wrote:i already worked on the same problem and couldn't find a satisfying algorithm. I didn't try it yet, but you could use the "harris corner detector" to get the most important corners in your picture. If an edge is matching at least two corners, its a good edge. At this way you can maybe get rid of "bad" edges.
Does harris corner detector really get all corners? I think I'll loose more edges with it if I combine the standard hough with finding line segments through harris corner detection, because some corners won't match the exact corners or are lost completely.
gnasen wrote:You could also try to use another convolution (I used sober instead of candy).
With sober you mean sobel? I don't know every of those algorithms, that's why I'm asking.

codewalker wrote:dude, you're blowing my mind :shock:
Zach wrote:QFT :|
:lol: :mrgreen:
bye,
Daniel
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Canny edge and now? Edge extraction - anyone?!

Post by gnasen »

DarkDragon wrote: Does harris corner detector really get all corners? I think I'll loose more edges with it if I combine the standard hough with finding line segments through harris corner detection, because some corners won't match the exact corners or are lost completely.
you have a variable called "corner response" k, which can be used to make the detector more strict or tolerant. I can send you a script with the background information if I can find it.
An idea would be to step through the "sharpness" of the detector and count how much edges would fall away with every step if you compare the edges with the corners. You could plot this as a step function f(k) = count_reject(k) / total_edges and maybe look for a max/min/inflection. Then take the result at step min/max/inflection. Just as an first idea.
DarkDragon wrote: With sober you mean sobel? I don't know every of those algorithms, that's why I'm asking.
yes sobel, sorry for the typo ;)
pb 5.11
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Canny edge and now? Edge extraction - anyone?!

Post by DarkDragon »

I have another idea and it seems to work somehow good already:
  1. Vectorize the edges as areas.
  2. To get poly-lines from the edges split the closed polygons, with the condition that every deleted segment from the polygon is either looking to the left or straight upwards.
Now you've got all segments from the polygon left, which look to the right or straight downwards. As they formed the edge of the edge you have to shift this a litte bit towards the edge (it matters in which order the polygons are defined, clockwise or anticlockwise).

With this you can get a perfect vectorization from your edges, but it seems to be a lot overkilled! And its buggy right now .. as some parts of the polygons aren't rejected.
bye,
Daniel
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Canny edge and now? Edge extraction - anyone?!

Post by idle »

without seeing what your input is it's really hard to say what would be the best method
houghs are really only of use when your looking for specific lines of interest

A canny is like a gausian blur with a sobel , did you try a laplacian? they often have better results for noise
Windows 11, Manjaro, Raspberry Pi OS
Image
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Canny edge and now? Edge extraction - anyone?!

Post by gnasen »

DarkDragon wrote:I have another idea and it seems to work somehow good already:
  1. Vectorize the edges as areas.
  2. To get poly-lines from the edges split the closed polygons, with the condition that every deleted segment from the polygon is either looking to the left or straight upwards.
Now you've got all segments from the polygon left, which look to the right or straight downwards. As they formed the edge of the edge you have to shift this a litte bit towards the edge (it matters in which order the polygons are defined, clockwise or anticlockwise)
Honestly, I dont get it. I think a little outline/picture would help much :)
pb 5.11
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Canny edge and now? Edge extraction - anyone?!

Post by DarkDragon »

Thanks for your answers.
idle wrote:without seeing what your input is it's really hard to say what would be the best method
My input consists of any photos chosen by the user. Then I modify it with an bilateral filter, convert it to grayscale and use the opencv canny edge variant (which is not a true canny edge, as there would be no sobel in it).
idle wrote:houghs are really only of use when your looking for specific lines of interest
Yes, I first thought that would be enough, but it isn't. Well I was able to filter the output of the probabilistic hough transformation, so that small parallel lines which have a small distance get connected to a bit longer lines.
idle wrote:A canny is like a gausian blur with a sobel , did you try a laplacian? they often have better results for noise
I didn't try yet, thanks for the hint. But the extraction of those lines is more a problem than canny edge itself. I would like to have an algorithm which lets me specify the segment minimum length and then it tries to fit the whole edge image with lines that are longer. Not only the best edges, also all other edges.
gnasen wrote:Honestly, I dont get it. I think a little outline/picture would help much :)
This sketch explains it, but I've changed the condition, as holes in polygons may produce the same edges again if you're not having all polygons described in the same way (clockwise or anticlockwise):
http://www.bradan.eu/files/vectorizationOfEdges.png

This works quite well, but in some situations it still has problems. And after this you can shift the lines towards the real edge with a simple shift by the edge normal and the dilatation radius.
If you want my full name for this new invented algorithm using marching squares, let me know or look at my homepage :lol: .
bye,
Daniel
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Canny edge and now? Edge extraction - anyone?!

Post by idle »

I still don't fully understand what you're aiming to achieve.
Do you have an example images of your input and the desired output?
It sounds like it'll be a difficult problem if it's intended to work on arbitrary input
and there are so many ways to skin the cat.
Windows 11, Manjaro, Raspberry Pi OS
Image
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Canny edge and now? Edge extraction - anyone?!

Post by DarkDragon »

idle wrote:I still don't fully understand what you're aiming to achieve.
Do you have an example images of your input and the desired output?
With this as input image I will get this from canny edge and then I want exactly those edges as vectorized polyline, or if not possible as longest lines approximation. For the longest lines is p. hough transformation enough, but for the smaller ones it creates lines which only hit the real edge by 2 pixels or such. And it cuts long lines in some cases. Have a look at this. The first car's side window is full of edges which are very small, but not really belonging to a real edge. P. Hough transformation is good for long lines, but I also need the small lines! My goal would be something like this if every connected color represents one vectorized line: http://en.wikipedia.org/wiki/File:Valve ... ur_(4).PNG and this was the input image: http://en.wikipedia.org/wiki/File:Valve ... ny_(6).PNG
idle wrote:It sounds like it'll be a difficult problem if it's intended to work on arbitrary input
and there are so many ways to skin the cat.
It doesn't need to be very fast. It is allowed to calculate a minute or two on a usual pc.
bye,
Daniel
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Canny edge and now? Edge extraction - anyone?!

Post by idle »

If you've got time to process the image then I'd probably go in to frequency space to process the image
and use a high pass filter like a butterworth to bring out the edges. Then use morphological operations
dilate and Errodes on the inversed FFT image.

You could possibly also use a hough in frequency space to find the best candidate angles
in the image or maybe even filter the FFT with the hough, never tried it so don't know if it'd work.

Don't know if openCV exports an FFT and filter functions but it will have one
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Canny edge and now? Edge extraction - anyone?!

Post by blueznl »

idle wrote:... I'd probably go in to frequency space to process the image and use a high pass filter like a butterworth to bring out the edges. Then use morphological operations dilate and Errodes on the inversed FFT image. You could possibly also use a hough in frequency space to find the best candidate angles in the image or maybe even filter the FFT with the hough, never tried it so don't know if it'd work. Don't know if openCV exports an FFT and filter functions but it will have one
Now, seriously, anybody ever wondered why they consider programmers 'geeks'? I mean, the last time a girl talked to me that way, I pulled up my trousers and left...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Canny edge and now? Edge extraction - anyone?!

Post by gnasen »

blueznl wrote:Now, seriously, anybody ever wondered why they consider programmers 'geeks'? I mean, the last time a girl talked to me that way, I pulled up my trousers and left...
good point ;)
pb 5.11
Post Reply