Page 1 of 1

mask - how to draw edge?

Posted: 2012-10-06T15:27:54-07:00
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

Re: mask - how to draw edge?

Posted: 2012-10-06T16:09:07-07:00
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

Re: mask - how to draw edge?

Posted: 2012-10-07T15:30:36-07:00
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)?

Re: mask - how to draw edge?

Posted: 2012-10-07T15:56:18-07:00
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

Re: mask - how to draw edge?

Posted: 2012-10-07T17:28:56-07:00
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

Re: mask - how to draw edge?

Posted: 2012-10-08T02:53:43-07:00
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.