Page 1 of 1

Detecting borders and Deskew

Posted: 2017-01-07T17:56:22-07:00
by ebr4him
Hi,

I'm want to extract street signs from photographs and deskew them, but I don't know where to begin.

Deskewing I believe is the easy part once the borders are detected?

Here're a few sample images: http://imgur.com/a/uESgY

This one especially seems to be the most challenging: http://imgur.com/x7dylYS

I'd really appreciate any help. Thanks!

Re: Detecting borders and Deskew

Posted: 2017-01-07T18:55:05-07:00
by fmw42
What is your IM version and platform? Please alway provide that.

From your images, it will be very hard to detect the boundary of the sign, since the background color in places is very close. You could try -hough-lines. Then find the major lines from the sign and get the intersections. See viewtopic.php?f=4&t=25476

For deskewing, see -deskew. Or get the 4 bounding corners and use +distort perspective to rectify the image to a proper orthogonal rectangle.

Re: Detecting borders and Deskew

Posted: 2017-01-07T19:17:01-07:00
by ebr4him
ebr4him@mac ~> convert -version
Version: ImageMagick 6.9.6-2 Q16 x86_64 2016-10-11 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

Re: Detecting borders and Deskew

Posted: 2017-01-07T19:18:14-07:00
by ebr4him
fmw42 wrote: From your images, it will be very hard to detect the boundary of the sign, since the background color in places is very close. You could try -hough-lines. Then find the major lines from the sign and get the intersections. See viewtopic.php?f=4&t=25476
Would converting it black & white and inverting the colors help?

Re: Detecting borders and Deskew

Posted: 2017-01-07T20:34:56-07:00
by fmw42
Would converting it black & white and inverting the colors help?
No, I doubt that would help, since the sign color and background color are close whether color or grayscale or black and white.

My best guess would be to do several fuzzy floodfills for each region in your sign and say make those white, then make the rest black.

Re: Detecting borders and Deskew

Posted: 2017-01-07T20:55:13-07:00
by ebr4him
Aha, so the signs are always just two colors: green & red. There's black for some signs, and blue for handicap. Only the black is an issue.

So you're saying floodfill those regions and then discard the rest?

Re: Detecting borders and Deskew

Posted: 2017-01-07T22:57:05-07:00
by fmw42
Aha, so the signs are always just two colors: green & red. There's black for some signs, and blue for handicap. Only the black is an issue.
I do not know that for a fact. But some of those colors may be nearly the same as the background.
So you're saying floodfill those regions and then discard the rest?
Not discard. Just make it so that the outer regions of the sign are distinct from the background. Then you can do hough lines to find the boundary of the sign and then intersect the lines to get the corners. Then use the corner points to do a perspective transform to rectify the sign to orthogonal rectangle (right angles) so as to deskew.