Page 1 of 1

Line Detection, Image Manipulation, and Data Extraction

Posted: 2017-01-16T01:38:26-07:00
by RAM2549
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.

Re: Line Detection, Image Manipulation, and Data Extraction

Posted: 2017-01-16T11:19:12-07:00
by fmw42
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.

Re: Line Detection, Image Manipulation, and Data Extraction

Posted: 2017-01-16T11:57:40-07:00
by snibgo
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.

Re: Line Detection, Image Manipulation, and Data Extraction

Posted: 2017-01-16T12:30:53-07:00
by fmw42
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.

Re: Line Detection, Image Manipulation, and Data Extraction

Posted: 2017-01-17T03:55:10-07:00
by RAM2549
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)