Create a solid line from stippled

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
meteorlologist
Posts: 3
Joined: 2015-11-17T22:06:44-07:00
Authentication code: 1151

Create a solid line from stippled

Post by meteorlologist »

Hi folks,
I am trying to create a solid border to overlay onto maps. I have a border that is very stippled, comprising of a bunch of dots. Is there any way to "connect the dots" and thicken the line so that I have a solid border to work with? It seems that it should be possible with -morphology but every approach I have tried does not work.

Image


Thanks for the help!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create a solid line from stippled

Post by snibgo »

The difficulty here is knowing what is a gap that needs filling, as opposed to a gap between two separate features. Can you say for sure what the gap size is that needs filling?

It looks like a plot from NGIS coastline data or similar, where the software has simply plotted the points without joining them up. And it might have been resized at some time. Getting better data may be a better solution.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a solid line from stippled

Post by fmw42 »

Does this help?

Code: Select all

convert oDsSkai.png -morphology erode diamond:1 result.png
If so, see http://www.imagemagick.org/Usage/morphology/
meteorlologist
Posts: 3
Joined: 2015-11-17T22:06:44-07:00
Authentication code: 1151

Re: Create a solid line from stippled

Post by meteorlologist »

I made the borders myself from a satellite image, so there was a lot of noise to try to filter through. This is the cleanest I've been able to come up with, once I got enough "coastline" to be solid I started picking up other data as well (trying to pull these out from a satpic with black or white borders, except the satellite data itself is often white and the land is black!).

I tried using erode diamond but it doesn't seem to make a difference.

Once I have a good coastline, I can re-use it forever. Might just take it into paint and color it by hand the old-fashioned way.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a solid line from stippled

Post by fmw42 »

For me, it made the line segments a bit longer and especially darker/thicker. What IM version and platform are you using?

You also can increase the diamond:1 to diamond:2 or use octagon or some other shape kernel.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create a solid line from stippled

Post by snibgo »

"-morphology open" may also be useful here.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a solid line from stippled

Post by fmw42 »

I originally tried -morphology open, but saw little or no change with diamond:1. I did not try larger kernels. So that is why I just used erode with as small a kernel as I could.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create a solid line from stippled

Post by snibgo »

For example:

Code: Select all

convert oDsSkai.png -morphology open disk:1 c.png
This fills some gaps in lines. However, it also fills small areas between lines, which may be undesirable.

I can't see a simple solution, but nor do I understand what result is wanted. If the OP edits a small portion of the image to be what is wanted, this might provide insight.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a solid line from stippled

Post by fmw42 »

In IM, I believe your best possibility is -morphology. IM does not have any function to follow lines and fill gaps. There is some code in the Canny edge detector to do some of that, but it relies upon a gradient image and you do not have that. If you started from a map with colored regions, you could try the Canny edge detector. See viewtopic.php?f=4&t=25405
meteorlologist
Posts: 3
Joined: 2015-11-17T22:06:44-07:00
Authentication code: 1151

Re: Create a solid line from stippled

Post by meteorlologist »

Thanks for the advice everyone. After trying several approaches, the solution is that this is a job for human intervention, I'll have to go through my satellite map and manually draw the borders in a unique color, then make all other colors transparent to pull out just the border outlines.

Not the fastest solution but probably the best, I only need one border map then I can overlay it forever. Thanks again for the advice!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a solid line from stippled

Post by fmw42 »

If you have a map that is colored regions rather than lines, then -Canny might help create an edge outline.
Post Reply