mask - how to draw edge?

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
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

mask - how to draw edge?

Post by Draoidh »

I have a mask, a background and a foreground image combining them with -compose.
I would like to draw an edge where the black and the white of the mask meet, similar to this example from the manual:'
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask - how to draw edge?

Post by fmw42 »

Use -edge or -morphology edge (or edgein or edgeout) on the mask to create a new blank/white edge image. Then use -compose screen to apply it to your previouls result. If done with parenthesis processing, it can all be done in one command line.

see
http://www.imagemagick.org/script/comma ... s.php#edge
http://www.imagemagick.org/Usage/morphology/#edgein
http://www.imagemagick.org/Usage/compose/#screen
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: mask - how to draw edge?

Post by Draoidh »

edgeout after some playing around with the kernels did it for me!

screen only seems useful if you want white text (as per the manual example)?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask - how to draw edge?

Post by fmw42 »

Take your white edge image and use it as a mask to overly a negated edge mask in a composite. Negating the edge image makes the edges black on white background, but the original edge images is the opposite and is used as the mask image. see http://www.imagemagick.org/Usage/compose/#compose

convert image \( whiteedge -negate \) whiteedge -compose over -composite result

alternately

convert image \( -clone -fill black -colorize 100% \) whiteedge -compose over -composite result
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: mask - how to draw edge?

Post by anthony »

For more ways see...
IM Examples, Transforms, Edge Outlines
http://www.imagemagick.org/Usage/transform/#edge_jitter

This looks at both anti-aliased shapes, and aliased bitmap shapes, as well as a vector approach.

NOTE drawing an edge is tricky as an edge has a 0 width, BUT lines have a a width of typically 1 pixel. This means a drawn edge may be inside, outside, to top-left of or bottom right of the actual edge. Idealy you would want the middle of an anti-aliased line to match the exact edge.

NOTE: drawn shapes does not draw edges exactly where specified, but at a point 1/2 pixel wider than it should be.
This means two shapes drawn using the same edge overlap by 1 pixel.

See Draw Fill Bounds
http://www.imagemagick.org/Usage/draw/#bounds
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: mask - how to draw edge?

Post by Draoidh »

Fred, thanks for confirming that the mask -compose approach is the way forward, which is what I did last night.

Anthony, these seem to be endless ways to skin the cat but in my particular case -morphology edge produced good results.

I must say it's damned handy youse two being in different timezones at the furthest away corners of your continents - Fred 8 hrs behind and Anthony 10 ahead! - particularly with me being night-active! ImageMagick covered 24/7.
Post Reply