Detecting borders and Deskew

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ebr4him
Posts: 13
Joined: 2015-07-20T13:50:23-07:00
Authentication code: 1151

Detecting borders and Deskew

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detecting borders and Deskew

Post 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.
ebr4him
Posts: 13
Joined: 2015-07-20T13:50:23-07:00
Authentication code: 1151

Re: Detecting borders and Deskew

Post 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
ebr4him
Posts: 13
Joined: 2015-07-20T13:50:23-07:00
Authentication code: 1151

Re: Detecting borders and Deskew

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detecting borders and Deskew

Post 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.
ebr4him
Posts: 13
Joined: 2015-07-20T13:50:23-07:00
Authentication code: 1151

Re: Detecting borders and Deskew

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detecting borders and Deskew

Post 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.
Post Reply