Create a Stencil Outline

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
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Create a Stencil Outline

Post by robocop »

Hello

I was looking for a way to convert my silhouette images into a stencil outline. Is there a way to do this correctly?

I have tried taking my silhouette image and applied the following 2 commands:
  • convert image.png -edge .5 -blur 0x.5 image_new.png
    convert image_new.png -negate image_final.png
And I get a pretty decent image created with the black silhouette fill removed and just a black outline border.

It does leave a bit of noise though around the border edges and the images are not super clean.

I was just wondering if there is a better way to do this. I'm probably doing it all wrong :lol:

Thank you
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Create a Stencil Outline

Post by Bonzo »

How about resizing the original, negating, change the black to transparent it then compositing it with gravity center back over the original?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a Stencil Outline

Post by fmw42 »

How about posting a link to your input image so we can see what you are trying to do.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Create a Stencil Outline

Post by Bonzo »

My method did not work very well:

Code: Select all

convert  input.gif ( input.gif -thumbnail 90% -negate -transparent black ) -gravity center -composite output.gif
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Re: Create a Stencil Outline

Post by robocop »

Hi! Thank you for sharing your thoughts.

The original image:
http://img43.imageshack.us/img43/5357/qlq.png

After i apply the command:
convert image.png -edge .5 -blur 0x.5 image_new.png

I get this image:
http://img443.imageshack.us/img443/1766/enit.png

and after i apply the second command:
convert image_new.png -negate image_final.png

I end up getting the desired outline on the image:
http://img850.imageshack.us/img850/7831/xwqj.png

But as you can see it's a little dirty around the edges.

I was hoping to get an output something similar to this:
http://www.clker.com/cliparts/z/l/W/s/U ... ine-md.png

Thanks very much!
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Re: Create a Stencil Outline

Post by robocop »

Thanks Bonzo.

I tried what you suggested but as you mentioned, it didn't come out very well :) Cheers
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a Stencil Outline

Post by fmw42 »

your image does not have a pure white outside (though it is not visible to eye). But if you threshold at 99% you will see it is "dirty". Also the boundary is antialiased.

try this

convert qlq.png -alpha off -gravity center -bordercolor white -border 5 -morphology edgeout diamond:1 -shave 5x5 -negate outline1.png

or

convert qlq.png -alpha off -gravity center -bordercolor white -border 5 -morphology edgein diamond:1 -shave 5x5 -negate outline2.png


see http://www.imagemagick.org/Usage/morphology/#difference



Or if you want binary, then

convert qlq.png -alpha off -gravity center -bordercolor white -border 5 -morphology edgeout diamond:1 -shave 5x5 -threshold 15% -negate outline3.png
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Re: Create a Stencil Outline

Post by robocop »

Sorry for the super late reply.

Thanks very much! The last one worked pretty well.

I appreciate the help
Thank you
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
Post Reply