Line Detection, Image Manipulation, and Data Extraction

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
RAM2549
Posts: 2
Joined: 2017-01-16T00:58:17-07:00
Authentication code: 1151

Line Detection, Image Manipulation, and Data Extraction

Post by RAM2549 » 2017-01-16T01:38:26-07:00

I am quite new to Imagemagick, but I am OK with programming in VB, Python and R.
I have a set of maps as images, with quite bad quality, and I would like to extract the county limits, that are in darker colour.
I tried edge detection, but I cannot make it return only the lines I want. I assume I need some pre-processing, but I am not sure what to do.
I have about 100 of these images, so I need a way to do this pretty automatic.

An example of one of the better images is here

Image
Any pointers will be appreciated.

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Line Detection, Image Manipulation, and Data Extraction

Post by fmw42 » 2017-01-16T11:19:12-07:00

This is rather hard, since the image is grayscale. Do you have a color version where the boundaries are a different color from most of the background? Then you could threshold on selected colors, followed by morphological open or close or by connected components processing.

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Line Detection, Image Manipulation, and Data Extraction

Post by snibgo » 2017-01-16T11:57:40-07:00

RAM2589 wrote:... but I cannot make it return only the lines I want.
You don't show us which lines you want. Which lines are county limits? The question is, what distinguishes these lines? "-threshold 33%" removes many marks that aren't the lines, but possibly also some relevant lines. If you only want the thick lines, then a morphology can probably get it, perhaps after removing small marks and thin marks.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Line Detection, Image Manipulation, and Data Extraction

Post by fmw42 » 2017-01-16T12:30:53-07:00

The county lines, I believe, are the dark lines with the county names inside them. A -threshold of about 15-20% keeps them, but also a lot of background lines and noise. So with grayscale it is hard to isolate just those lines.

RAM2549
Posts: 2
Joined: 2017-01-16T00:58:17-07:00
Authentication code: 1151

Re: Line Detection, Image Manipulation, and Data Extraction

Post by RAM2549 » 2017-01-17T03:55:10-07:00

Thank you all for the good replies. Sorry for not being precise enough. I want to get the thickest lines, and the second-thickest lines inside the polygon defined by the thickest ones. I am looking for something like the image below (made using GIMP, and selecting the lines I want by hand - not looking forward to do this on 100+ images).
Image
I guess you hit the nail, all I have are these grayscale images. There is no way I will get the colour ones. That is why I am looking for a more elaborate algorithm to get them....

I thought about following this workflow:
1) first selecting the thickest line
2) define a polygon using this line
3) remove everything outside it
4) get the thickest inside the polygon.

But I do not know how to do this properly... (or even if it would work)

Post Reply