Page 1 of 2

How to erase shoreline but preserve admin land borders?

Posted: 2017-06-22T12:44:17-07:00
by yarr
Hello

I need to separate and remove shoreline from the administrative boundaries mask.
The best result I achieved with these two commands:

Code: Select all

convert admin_borders.png \( oceanmask.png -blur 0x5 -level 99,100% \) \
	-compose In -composite admin_borders_choked.png

convert oceanmask.png -background Navy -alpha shape admin_borders_choked.png \
	-compose Screen -composite admin_borders_no_shoreline.png
but they are not sufficient when applied to developed shoreline.

Target images are much larger (7680 width) and lines are 3px width.

Can you please help me improve this procedure?

yarr
ImageMagick 6.9.2-0 Q16 x64 2015-08-15

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-22T12:57:25-07:00
by fmw42
I am not sure I understand what you are trying to do and which lines you want to remove. Can you explain better or mark on your images what you want to remove. Do you only want the white lines in admin_borders_choked.png to show on admin_borders_no_shoreline.png or do you want the shoreline (dark borders) to show in white on the admin_borders_no_shoreline.png. Or do you want both white and black lines to show as white on your admin_borders_no_shoreline.png

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-22T13:02:51-07:00
by fmw42
You do not say what platform/OS you are using and your syntax seems mixed between Window and Unix.

Try this:

Window:

Code: Select all

convert admin_borders.png ( oceanmask.png -blur 0x5 -level 99,100% ) ^
-compose In -composite -solarize 50% -level 0x50% -negate admin_borders_choked2.png

Code: Select all

convert oceanmask.png -background Navy -alpha shape admin_borders_choked2.png ^
-compose Screen -composite admin_borders_no_shoreline2.png
Unix:

Code: Select all

convert admin_borders.png \( oceanmask.png -blur 0x5 -level 99,100% \) \
-compose In -composite -solarize 50% -level 0x50% -negate admin_borders_choked2.png

Code: Select all

convert oceanmask.png -background Navy -alpha shape admin_borders_choked2.png \
-compose Screen -composite admin_borders_no_shoreline2.png

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T03:33:51-07:00
by yarr
Thank you, Fred.

Generally I use Windows but its scripting environment is too lazy so I often use Cygwin console too.
Sorry for this mixed syntax - I know the difference between systems.

I would like only to preserve white borders between countries.
Shoreline should be removed but it should be done as thoroughly as possible.

admin_borders_no_shoreline.png file is only for demonstration purpose.

Target file is: admin_borders_choked.png - white transparent lines without traces of shoreline.

Source files comes from vector shapefiles so I can render them much larger if it can help simplifying procedure.

yarr

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T09:21:11-07:00
by fmw42
One observation -- your maps are not properly registered such that in many places they do not overlap. That is, features move when alternating the images. This makes it harder.

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T10:17:09-07:00
by yarr
They are both rendered from the same cartographic shape with same compression/palette settings.
I don't know what how to prepare them better.
Maybe it would be easier to cut borders before conversion to grayscale PNG?
(Originals are rendered as black & white images.)
Yes, I know this is not trivial task - that's why I asked you for help.

Forgive my English please.

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T11:11:38-07:00
by fmw42
Try the following using connected components labeling to remove small blobs. I first remove the transparency. The second example, I add the transparency back again. See http://magick.imagemagick.org/script/co ... onents.php

Input:
Image



Here is what it looks like without the alpha channel (see -alpha off -threshold 0 below):
Image


Code: Select all

convert admin_borders_choked.png -alpha off -threshold 0 \
-define connected-components:area-threshold=75 \
-define connected-components:mean-color=true \
-connected-components 8 \
admin_borders_clean.png
Image

or

Code: Select all

convert admin_borders_choked.png -alpha off -threshold 0 \
-define connected-components:area-threshold=75 \
-define connected-components:mean-color=true \
-connected-components 8 \
-transparent black admin_borders_clean_trans.png
Image

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T12:05:34-07:00
by yarr
Fred, both commands produce black image in my environment.

Image: admin_borders_clean.png

Code: Select all

  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 1536x864+0+0
  Units: Undefined
  Type: Grayscale
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 16-bit
  Channel depth:
    gray: 16-bit
  Channel statistics:
    Pixels: 1327104
    Gray:
      min: 0 (0)
      max: 21 (0.000320439)
      mean: 0.0524578 (8.00455e-007)
      standard deviation: 0.997415 (1.52196e-005)
      kurtosis: 370.802
      skewness: 19.2773
      entropy: 0.0171581
  Colors: 4
  Histogram:
   1322924: (    0,    0,    0) #000000000000 gray(0)
       641: (    2,    2,    2) #000200020002 gray(0.0030518%)
      2992: (   19,   19,   19) #001300130013 gray(0.0289921%)
       547: (   21,   21,   21) #001500150015 gray(0.0320439%)
  Rendering intent: Undefined
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1536x864+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2017-06-23T20:53:28+02:00
    date:modify: 2017-06-23T20:59:07+02:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45455 (See Gamma, above)
    png:IHDR.bit-depth-orig: 16
    png:IHDR.bit_depth: 16
    png:IHDR.color-type-orig: 0
    png:IHDR.color_type: 0 (Grayscale)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 1536, 864
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    png:tIME: 2017-06-23T20:59:07Z
  Artifacts:
    filename: admin_borders_clean.png
    verbose: true
  Tainted: False
  Filesize: 4.38KB
  Number pixels: 1.327M
  Pixels per second: 102.1MB
  User time: 0.016u
  Elapsed time: 0:01.013
Image: admin_borders_clean_trans.png

Code: Select all

  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 1536x864+0+0
  Units: Undefined
  Type: GrayscaleAlpha
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 16-bit
  Channel depth:
    gray: 16-bit
    alpha: 1-bit
  Channel statistics:
    Pixels: 1327104
    Gray:
      min: 0 (0)
      max: 21 (0.000320439)
      mean: 0.0524578 (8.00455e-007)
      standard deviation: 0.997415 (1.52196e-005)
      kurtosis: 370.802
      skewness: 19.2773
      entropy: 0.0171581
    Alpha:
      min: 0 (0)
      max: 65535 (1)
      mean: 206.417 (0.00314972)
      standard deviation: 3672.18 (0.0560339)
      kurtosis: 312.492
      skewness: -17.7339
      entropy: 0.0153564
  Alpha: graya(0,0)   #0000000000000000
  Colors: 4
  Histogram:
   1322924: (    0,    0,    0,    0) #0000000000000000 graya(0,0)
       641: (    2,    2,    2,65535) #000200020002FFFF graya(0.0030518%,1)
      2992: (   19,   19,   19,65535) #001300130013FFFF graya(0.0289921%,1)
       547: (   21,   21,   21,65535) #001500150015FFFF graya(0.0320439%,1)
  Rendering intent: Undefined
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: graya(255,1)
  Border color: graya(223,1)
  Matte color: graya(189,1)
  Transparent color: graya(0,0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1536x864+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2017-06-23T20:53:28+02:00
    date:modify: 2017-06-23T20:59:08+02:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45455 (See Gamma, above)
    png:IHDR.bit-depth-orig: 16
    png:IHDR.bit_depth: 16
    png:IHDR.color-type-orig: 0
    png:IHDR.color_type: 0 (Grayscale)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 1536, 864
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    png:tIME: 2017-06-23T20:59:07Z
    png:tRNS: chunk was found
  Artifacts:
    filename: admin_borders_clean_trans.png
    verbose: true
  Tainted: False
  Filesize: 4.4KB
  Number pixels: 1.327M
  Pixels per second: 88.48MB
  User time: 0.016u
  Elapsed time: 0:01.014

Code: Select all


Version: ImageMagick 6.9.2-0 Q16 x64 2015-08-15 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC
Delegates (built-in): bzlib cairo freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T12:35:59-07:00
by Bonzo
Fred, both commands produce black image in my environment.
What environment, what exact code are you running? Instead of using some mish-mash why not settle on one method or the other and get the code working first?

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T13:05:09-07:00
by yarr

Code: Select all

convert admin_borders.png \
	\( oceanmask.png -blur 0x5 -level 99,100% \) -compose In -composite \
	admin_borders_choked.png

# first command
convert admin_borders_choked.png -alpha off -threshold 0 \
	-define connected-components:area-threshold=75 \
	-define connected-components:mean-color=true \
	-connected-components 8 \
	admin_borders_clean.png

# second command
convert admin_borders_choked.png -alpha off -threshold 0 \
	-define connected-components:area-threshold=75 \
	-define connected-components:mean-color=true \
	-connected-components 8 -transparent black \
	admin_borders_clean_trans.png

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T13:14:13-07:00
by fmw42
Is there a question here? My commands are Unix syntax. Be sure that when you run them you remove any blank spaces after the ending \, if you just copied and pasted. Your versions of ImageMagick is about 70 versions old. You might consider upgrading. Were there any error messages?

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T13:17:34-07:00
by yarr
None of this commands worked.
All right, I will upgrade IM and tell you if it helps.

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T13:21:55-07:00
by fmw42
I just reran your commands and it works fine for me.

Code: Select all

convert admin_borders.png \
\( oceanmask.png -blur 0x5 -level 99,100% \) -compose In -composite \
admin_borders_choked.png

convert admin_borders_choked.png -alpha off -threshold 0 \
-define connected-components:area-threshold=75 \
-define connected-components:mean-color=true \
-connected-components 8 \
admin_borders_clean.png

convert admin_borders_choked.png -alpha off -threshold 0 \
-define connected-components:area-threshold=75 \
-define connected-components:mean-color=true \
-connected-components 8 -transparent black \
admin_borders_clean_trans.png
Perhaps there is a bug in your version of ImageMagick. Can you upgrade? What is your version of libpng? See

convert -list format

and look at the PNG line. Mine is

PNG* PNG rw- Portable Network Graphics (libpng 1.6.29)

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T13:24:05-07:00
by fmw42
Did you use Cygwin? What is your ImageMagick version in Cygwin?

Re: How to erase shoreline but preserve admin land borders?

Posted: 2017-06-23T13:27:19-07:00
by yarr
PNG* rw- Portable Network Graphics (libpng 1.6.17)

I use Windows but I tried Cygwin also.
No matter what I use - commands don't work.
I will upgrade IM. Maybe it will help.

Thanks.