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
Any pointers will be appreciated.
Line Detection, Image Manipulation, and Data Extraction
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Line Detection, Image Manipulation, and Data Extraction
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Line Detection, Image Manipulation, and Data Extraction
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.RAM2589 wrote:... but I cannot make it return only the lines I want.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Line Detection, Image Manipulation, and Data Extraction
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
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).
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)
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)